c# - 压缩图像后它最终旋转
问题描述
您好,我有本教程来尝试压缩图像,但是,当我在手机(自拍)上使用个人资料照片时,它只会旋转 45 度。
会发生什么?
编辑
我添加了代码给你看,所以没有必要点击链接
private void VaryQualityLevel()
{
// Get a bitmap. The using statement ensures objects
// are automatically disposed from memory after use.
using (Bitmap bmp1 = new Bitmap(@"C:\TestPhoto.jpg"))
{
ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg);
// Create an Encoder object based on the GUID
// for the Quality parameter category.
System.Drawing.Imaging.Encoder myEncoder =
System.Drawing.Imaging.Encoder.Quality;
// Create an EncoderParameters object.
// An EncoderParameters object has an array of EncoderParameter
// objects. In this case, there is only one
// EncoderParameter object in the array.
EncoderParameters myEncoderParameters = new EncoderParameters(1);
// Save the bitmap as a JPG file with 10 quality level compression.
myEncoderParameter = new EncoderParameter(myEncoder, 10L);
myEncoderParameters.Param[0] = myEncoderParameter;
bmp1.Save(@"C:\TestPhotoQualityZero.jpg", jpgEncoder, myEncoderParameters);
}
}
这是代码的另一部分:
private ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FormatID == format.Guid)
{
return codec;
}
}
return null;
}
解决方案
推荐阅读
- wordpress - wordpress 的 wp_query 中的 show_post 不能正常工作
- docker - 在 Gitlab CI 中构建期间将 .env-File 添加到 Docker-Image 的最佳实践
- c# - 保持 Windows 应用程序处于活动状态,直到进程停止..C#
- java - 如果数据不可用,则在开始时禁用 Edittexts 并导航到另一个活动
- unity3d - 如果您引用它,Firebase 实时数据库是否总是读取完整的节点?
- windows - windbg, windows 打印驱动
- firebase - 在 Flutter 中搜索后如何导航到详细信息页面
- batch-file - 制作批处理文件以将文件夹的内容压缩到单独的 zip 中
- git - 如何压缩分支中的提交并重新设置它的所有后代分支?
- css - Vue-Bootstrap 在表格中添加特殊行