Bir görüntünün Exif etiketi "Yönlendirme" nin değiştirilmesi

Dec 14 2020

Kod ile belirli bir görüntü için Exif etiketini "Yönlendirme" (0x0112) değiştirmeye çalışıyorum .

Burada okumakla ilgili çalışan bir örnek buldum ama aynı etiketi yazmakta başarısız oluyorum.

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;

Çalışma zamanında EAccessViolation, GPImage.SetPropertyItem(PI);satırda aşağıdakileri yükseltir :

757A8E30 adresinde 'msvcrt.dll' modülünde erişim ihlali. 00000006 adresinin okunması.

Bu benim test_up.jpg dosyam :

Yanıtlar

1 fpiette Dec 14 2020 at 16:09

Bu kodu başarıyla kullanıyorum:

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;

Bu, uygulamamda yazdığım bir işlev. GitHub'da tam kaynak kodu .