我正在尝试通过代码更改给定图像的Exif 标记“方向”(0x0112)。
在这里,我找到了一个关于阅读的工作示例,但我无法编写相同的标签。
uses
GDIPAPI, GDIPOBJ, GDIPUTIL;
var
GPImage: TGPImage;
BufferSize: Cardinal;
Orientation: Byte;
RotateType: TRotateFlipType;
EncoderClsid: TGUID;
PI : PropertyItem;
begin
GPImage := TGPImage.Create('.\test_up.jpg');
try
BufferSize := GPImage.GetPropertyItemSize(PropertyTagOrientation);
if BufferSize <= 0
then raise Exception.Create('BufferSize <= 0');
Orientation := 6; //this should be Rotate90FlipNone
PI.id := PropertyTagOrientation;
PI.type_ := 3;
PI.length := BufferSize;
PI.value := PByte(Orientation);
GPImage.SetPropertyItem(PI);
GetEncoderClsid('image/jpeg', EncoderClsid);
GPImage.Save('.\test_up_Rotate90FlipNone.jpg', EncoderClsid);
finally
GPImage.Free
end;
end;
EAccessViolation在运行时,它会在该GPImage.SetPropertyItem(PI);行引发以下内容:
模块“msvcrt.dll”中地址 757A8E30 的访问冲突。读取地址 00000006。
这是我的test_up.jpg:
