एक छवि का Exif टैग "ओरिएंटेशन" बदलना
Dec 14 2020
मैं कोड द्वारा दिए गए चित्र के लिए 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 है :

जवाब
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 पर पूर्ण स्रोत कोड ।