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
| unit UAFPhoto;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ExtDlgs;
type
TForm2 = class(TForm)
Image1: TImage;
Button1: TButton;
OpenPictureDialog1: TOpenPictureDialog;
procedure Button1Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form2 : TForm2;
implementation
uses AnsiStrings,
// l'unité de Paul Toth
// https://github.com/tothpaul/Delphi/tree/master/GDIPBitmap
// https://www.developpez.net/forums/d1783447/environnements-developpement/delphi/contribuez/lire-fichiers-jpg-png-tif-quelques-lignes-code/
Execute.GDIPBitmap;
{$R *.dfm}
const
PngHeader : array[0..7] of AnsiChar = (#137, #80, #78, #71, #13, #10, #26, #10);
var
SearchInBin : AnsiString; // Fichier afphoto
function afLoadPNGThumb(const aFileName: string; const aImage: TImage): Boolean;
var
Po : Integer;
Ms : TMemoryStream;
begin
Result := False;
if (not FileExists(aFileName)) or (not Assigned(aImage)) then
Exit;
MS := TMemoryStream.Create;
with MS do
try
LoadFromFile(aFileName);
Seek(0, soFromBeginning);
SetLength(SearchInBin, Size);
MoveMemory(PByte(SearchInBin), Memory, Size);
// Recherche d'une Image PNG dans un Fichier *.afphoto
Po := PosEx(PngHeader, SearchInBin, 1);
if Po <> 0 then
begin
MS.SetSize(Size - Po);
MoveMemory(Memory, PByte(@SearchInBin[po]), Size);
aImage.Picture.Bitmap.GDIPLoadFromStream(MS);
Result := True;
end;
finally
MS.Free;
end;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
OpenPictureDialog1.Filter := 'Affinity Photo|*.afphoto';
if OpenPictureDialog1.Execute then
afLoadPNGThumb(OpenPictureDialog1.FileName, Image1);
end;
end. |
Partager