Why does TImage rotate my image?

Writing a mobile application - it pulls images from a secure website and shown below (the first image) does not pull correctly (pay attention to the web version and the mobile version), the second image displays correctly on the website, but Delphi TImage rotates it for some reason then, and I can’t understand why. The rotation is set to 0, and the "Fit" parameter is set to the TImage component.

Thoughts?

enter image description here

Why does it rotate like this:> </a> </p></div></body> </html>

+6
source share
4 answers

The Exif specification defines an Orientation tag indicating the orientation of the camera relative to the captured scene. Therefore, some applications may automatically rotate the image corresponding to this EXIF ​​flag. I would suggest that your web version makes it rotate automatically. TImage does not do this.

+7
source

Jpeg and Tiff have Exif (pluggable image file format) that determine the orientation of the image (among other data).

It's not that "TImage rotates my image." TImage does not process Exif orientation metadata. Ideally, TImage should automatically rotate the image according to the orientation metadata, but this is not the case. You need to read the Exif orientation property and rotate the image accordingly.

Exif tag "Orientation" (0x0112):

1 = Horizontal (normal) 2 = Mirror horizontal 3 = Rotate 180 4 = Mirror vertical 5 = Mirror horizontal and rotate 270 CW 6 = Rotate 90 CW 7 = Mirror horizontal and rotate 90 CW 8 = Rotate 270 CW 

You can use some free Exif components like TExif / NativeJpg / CCR Exif and, if necessary, rotate the image according to the orientation tag.

Here is an example of using GDI + (VCL / Windows), for example:

 uses GDIPAPI, GDIPOBJ; procedure TForm1.Button1Click(Sender: TObject); var GPImage: TGPImage; GPGraphics: TGPGraphics; pPropItem: PPropertyItem; BufferSize: Cardinal; Orientation: Byte; RotateType: TRotateFlipType; Bitmap: TBitmap; begin GPImage := TGPImage.Create('D:\Test\image.jpg'); try BufferSize := GPImage.GetPropertyItemSize(PropertyTagOrientation); if BufferSize > 0 then begin GetMem(pPropItem, BufferSize); try GDPImage.GetPropertyItem(PropertyTagOrientation, BufferSize, pPropItem); Orientation := PByte(pPropItem.value)^; case Orientation of 1: RotateType := RotateNoneFlipNone; // Horizontal - No rotation required 2: RotateType := RotateNoneFlipX; 3: RotateType := Rotate180FlipNone; 4: RotateType := Rotate180FlipX; 5: RotateType := Rotate90FlipX; 6: RotateType := Rotate90FlipNone; 7: RotateType := Rotate270FlipX; 8: RotateType := Rotate270FlipNone; else RotateType := RotateNoneFlipNone; // Unknown rotation? end; if RotateType <> RotateNoneFlipNone then GPImage.RotateFlip(RotateType); Bitmap := TBitmap.Create; try Bitmap.Width := GPImage.GetWidth; Bitmap.Height := GPImage.GetHeight; Bitmap.Canvas.Lock; try GPGraphics := TGPGraphics.Create(Bitmap.Canvas.Handle); try GPGraphics.DrawImage(GPImage, 0, 0, GPImage.GetWidth, GPImage.GetHeight); Image1.Picture.Assign(Bitmap); finally GPGraphics.Free; end; finally Bitmap.Canvas.Unlock; end; finally Bitmap.Free; end; finally FreeMem(pPropItem); end; end; finally GPImage.Free end; end; 
+5
source

The website certainly reads the exif image data that contains the orientation of the photo, and then rotates the image accordingly. Delphi does not. You must read the image metadata for this (search for "exif" on google)

+2
source

Thanks to everyone.

Not a programming solution, but worked for me ....

I used the free InfranView image processing software to check images and turned off EXIF ​​read data that showed me images that were not rotated correctly. I changed and re-saved the files and updated the website.

0
source

Source: https://habr.com/ru/post/1014028/


All Articles