0

Hello I have this tutorial to try to get an image compressed, however, when I use a profile photo with my phone(selfie) it just rotates 45 degrees.

What could be happening?

EDIT

I added the code to show you, so it is not necessary to click the link

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);  
    }  
}  

This is the other portion of code:

private ImageCodecInfo GetEncoder(ImageFormat format)  
{  
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();  
foreach (ImageCodecInfo codec in codecs)  
{  
    if (codec.FormatID == format.Guid)  
    {  
        return codec;  
    }  
}  
return null;  

}

ev vk
  • 345
  • 1
  • 4
  • 18
  • 2
    Either you rotated the image in code or it was already rotated. It's impossible to guess withouth the code – Panagiotis Kanavos Mar 06 '19 at 10:21
  • 4
    The exeif orientation flag of your jpeg gets lost after converting. https://stackoverflow.com/q/27835064/1315444 – fubo Mar 06 '19 at 10:21
  • 1
    Or rather, compression creates a *new* image using the *contents* of the old one, not the metadata. You'd have to copy any metadata to the new image to preserve them, including the orientation – Panagiotis Kanavos Mar 06 '19 at 10:23
  • what is odd, is that when I upload any image from internet, not from my camera, that image does not flip – ev vk Mar 06 '19 at 10:27
  • Usually the images are not really flipped but only an orientation tag is set. Some program do use it others don't.. – TaW Mar 06 '19 at 11:50

0 Answers0