1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| unit Unit16;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtDlgs,
Vcl.ExtCtrls,
Vcl.Imaging.jpeg;
type
TForm16 = class(TForm)
Button1: TButton;
Image1: TImage;
OpenPictureDialog1: TOpenPictureDialog;
procedure Button1Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form16: TForm16;
implementation
{$R *.dfm}
uses Winapi.GDIPApi, Winapi.GDIPObj, Winapi.GDIPUTIL;
procedure TForm16.Button1Click(Sender: TObject);
var
GPImage: TGPImage;
GPGraphics: TGPGraphics;
pPropItem: PPropertyItem;
BufferSize: Cardinal;
Orientation: Byte;
RotateType: TRotateFlipType;
Bitmap: TBitmap;
begin
if OpenPictureDialog1.Execute then
begin
GPImage := TGPImage.Create(OpenPictureDialog1.FileName);
try
// extraction EXIF
// BufferSize := GPImage.GetPropertyItemSize(PropertyTagOrientation);
// if BufferSize > 0 then
// begin
// GetMem(pPropItem, BufferSize);
// try
// GPImage.GetPropertyItem(PropertyTagOrientation, BufferSize, pPropItem);
// Orientation := PByte(pPropItem.value)^;
// case Orientation of
// 1: RotateType := RotateNoneFlipNone; // Horizontal - pas de rotation
// 2: RotateType := RotateNoneFlipX;
// 3: RotateType := Rotate180FlipNone;
// 4: RotateType := Rotate180FlipX;
// 5: RotateType := Rotate90FlipX;
// 6: RotateType := Rotate90FlipNone;
// 7: RotateType := Rotate270FlipX;
// 8: RotateType := Rotate270FlipNone;
// else
// RotateType := RotateNoneFlipNone
// end;
// finally
// FreeMem(pPropItem);
// end;
RotateType := Rotate180FlipNone; // un choix de ma part
// if RotateType <> RotateNoneFlipNone then
GPImage.RotateFlip(RotateType);
Bitmap := TBitmap.Create;
try
Bitmap.Width := GPImage.GetWidth;
Bitmap.Height := GPImage.GetHeight;
Bitmap.Canvas.Lock;
try
GPGraphics := TGPGraphics.Create(Bitmap.Canvas.Handle);
try
GPGraphics.DrawImage(GPImage, 0, 0, GPImage.GetWidth,
GPImage.GetHeight);
Image1.Picture.Assign(Bitmap);
finally
GPGraphics.Free;
end;
finally
Bitmap.Canvas.Unlock;
end;
finally
Bitmap.Free;
end;
// end;
finally
GPImage.Free
end;
end;
end; |
Partager