We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Exception when AutoRotate

I have image which causes exception during AutoRotate. Here is a sample program:
TestApp.zip (970.1 KB)

Steps to reproduce:

  1. Open project in VS and run it
  2. Press the button. You should see the exception

If you need more info, please let me know.

Thanks

Hello, @mmdevelopment,
Let me take a look at your case. You are going to get our feedback soon!

@mmdevelopment,
Here is a work-around for you:

private static MemoryStream AutoRotateImage(byte[] imageBytes)
{
    var testStream = new MemoryStream(imageBytes)
    {
        Position = 0
    };

    using var image = Aspose.Imaging.Image.Load(testStream);

    // there is enum ExifOrientation that specifies image rotation
    // ExifOrientation values are enumerated from 1 to 8, so any other value causes exception
    // in this case input image has exif.Orientation value of 0, so exception is thrown
    if (image is JpegImage jpeg && jpeg.ExifData is JpegExifData exif && Enum.IsDefined<ExifOrientation>(exif.Orientation))
    {
        jpeg.AutoRotate();

        testStream = new MemoryStream();
        jpeg.Save(testStream);
        testStream.Position = 0;
    }

    return testStream;
}