Zac*_*rns 6 delphi timage firemonkey
编写移动应用程序 - 它从安全网站中提取图像,如下图所示(第一张图像)拉不正确(通知网页版本与移动版本),第二张图片在网站上正确显示,但德尔福TImage因某种原因正在旋转它我无法弄清楚为什么.旋转设置为0,并在TImage组件上设置"适合".
思考?
Exif规范定义了一个Orientation Tag,用于指示摄像机相对于捕获场景的方向.因此,某些应用可以自动旋转与此EXIF标志对应的图像.我猜你的网络版本会自动旋转.TImage不这样做.
Jpeg和Tiff具有指定图像方向的Exif(可交换图像文件格式)元数据(以及其他数据).
这不是"TImage旋转我的形象".TImage不处理Exif方向元数据.理想情况下,TImage 应根据方向元数据自动旋转图像,但事实并非如此.您需要阅读Exif方向属性并相应地旋转图像.
该Exif标签 "方向"(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
Run Code Online (Sandbox Code Playgroud)
您可以使用一些免费的Exif 组件, 如TExif/NativeJpg/CCR Exif,并根据方向标记根据需要旋转图像.
以下是使用GDI +(VCL/Windows)的示例,例如:
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;
Run Code Online (Sandbox Code Playgroud)