Zmiana tagu Exif obrazu „Orientacja”
Dec 14 2020
Próbuję zmienić tag Exif „Orientacja” (0x0112) dla danego obrazu za pomocą kodu.
Tutaj znalazłem działający przykład dotyczący czytania, ale nie udaje mi się napisać tego samego tagu.
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;
W czasie wykonywania wywołuje EAccessViolation
w GPImage.SetPropertyItem(PI);
linii następujące informacje:
Naruszenie dostępu pod adresem 757A8E30 w module „msvcrt.dll”. Odczyt adresu 00000006.
To jest mój test_up.jpg :

Odpowiedzi
1 fpiette Dec 14 2020 at 16:09
Z powodzeniem używam tego kodu:
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;
To jest funkcja, którą napisałem w mojej aplikacji. Pełny kod źródłowy na GitHub .