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
| implementation
{$R *.dfm}
uses
LibTiffDelphi;
procedure TIFFReadRGBAImageSwapRB(Width,Height: Cardinal; Memory: Pointer);
{$IFDEF DELPHI_5}
type
PCardinal = ^Cardinal;
{$ENDIF}
var
m: PCardinal;
n: Cardinal;
o: Cardinal;
begin
m:=Memory;
for n:=0 to Width*Height-1 do
begin
o:=m^;
m^:= (o and $FF00FF00) or
((o and $00FF0000) shr 16) or
((o and $000000FF) shl 16);
Inc(m);
end;
end;
function LoadTiffIntoBitmap(const Filename: String): TBitmap;
var
OpenTiff: PTIFF;
FirstPageWidth,FirstPageHeight: Cardinal;
FirstPageBitmap: TBitmap;
begin
OpenTiff:=TIFFOpen(Filename,'r');
TIFFGetField(OpenTiff,TIFFTAG_IMAGEWIDTH,@FirstPageWidth);
TIFFGetField(OpenTiff,TIFFTAG_IMAGELENGTH,@FirstPageHeight);
FirstPageBitmap:=TBitmap.Create;
FirstPageBitmap.PixelFormat:=pf32bit;
FirstPageBitmap.Width:=FirstPageWidth;
FirstPageBitmap.Height:=FirstPageHeight;
TIFFReadRGBAImage(OpenTiff,FirstPageWidth,FirstPageHeight,
FirstPageBitmap.Scanline[FirstPageHeight-1],0);
TIFFClose(OpenTiff);
TIFFReadRGBAImageSwapRB(FirstPageWidth,FirstPageheight,
FirstPageBitmap.Scanline[FirstPageHeight-1]);
Result:=FirstPageBitmap;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
BMP: TBitmap;
begin
BMP.Assign(LoadTiffIntoBitmap('ARGOS_4202_24-06-13.indd (Y).TIF'));
end;
end. |
Partager