首页 > 解决方案 > 压缩图像后它最终旋转

问题描述

您好,我有本教程来尝试压缩图像,但是,当我在手机(自拍)上使用个人资料照片时,它只会旋转 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;  

}

标签: c#image-compression

解决方案


推荐阅读