이미지의 Exif 태그 "방향"변경
Dec 14 2020
주어진 이미지에 대한 Exif 태그 "Orientation"(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입니다 .

답변
1 fpiette Dec 14 2020 at 16:09
이 코드를 성공적으로 사용하고 있습니다.
procedure TOvbCustomImage.SetImageOrientation(AGPImage: TGPImage; Value: WORD);
var
PropItem : TPropertyItem;
begin
if not Assigned(AGPImage) then
Exit;
PropItem.Id := PropertyTagOrientation;
PropItem.Length := SizeOf(WORD);
PropItem.Type_ := PropertyTagTypeShort;
PropItem.Value := @Value;
AGPImage.SetPropertyItem(PropItem);
end;
이것은 내 응용 프로그램에서 작성한 함수입니다. GitHub의 전체 소스 코드 .