如何显示 TIFF?
How to display a TIFF?
我想使用 pascal 将 .tif 显示到 delphi 并且我已经在使用 LibTiff
var
OpenTiff: PTIFF;
FirstPageWidth,FirstPageHeight: Cardinal;
FirstPageBitmap: TBitmap;
begin
OpenTiff:=TIFFOpen('C:\World.tif','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]);
end;
但是为什么图片不显示?有人有解决办法吗?对不起我的英语不好。
使用下面的代码将 tiff 转换为位图。
然后照常显示位图。
这是您正在使用的完整函数(有一些改动)。
function ReadTiffIntoBitmap(const Filename: string): TBitmap;
var
OpenTiff: PTIFF;
FirstPageWidth, FirstPageHeight: Cardinal;
begin
Result:= nil; //in case you want to tweak code to not raise exceptions.
OpenTiff:= TIFFOpen(Filename,'r');
if OpenTiff = nil then raise Exception.Create(
'Unable to open file '''+Filename+'''');
try
TIFFGetField(OpenTiff, TIFFTAG_IMAGEWIDTH, @FirstPageWidth);
TIFFGetField(OpenTiff, TIFFTAG_IMAGELENGTH, @FirstPageHeight);
Result:= TBitmap.Create;
try
Result.PixelFormat:= pf32bit;
Result.Width:= FirstPageWidth;
Result.Height:= FirstPageHeight;
except
FreeAndNil(Result);
raise Exception.Create('Unable to create TBitmap buffer');
end;
TIFFReadRGBAImage(OpenTiff, FirstPageWidth, FirstPageHeight,
Result.Scanline[FirstPageHeight-1],0);
TIFFReadRGBAImageSwapRB(FirstPageWidth, FirstPageheight,
Result.Scanline[FirstPageHeight-1]);
finally
TIFFClose(OpenTiff);
end;
end;
现在在以下上下文中使用它:
在表单上放置一个按钮和一个图像。
双击按钮并填充按钮的 OnClick 处理程序,如下所示:
Form1.Button1Click(sender: TObject);
var
MyBitmap: TBitmap;
begin
MyBitmap:= ReadTiffIntoBitmap('c:\test.tiff');
try
//uncomment if..then if ReadTiffIntoBitmap does not raise exceptions
//but returns nil on error instead.
{if Assigned(MyBitmap) then} Image1.Picture.Assign(MyBitmap);
finally
MyBitmap.Free;
end;
end;
我在以下位置找到了您的代码段的完整版本:http://www.asmail.be/msg0055571626.html
我想使用 pascal 将 .tif 显示到 delphi 并且我已经在使用 LibTiff
var
OpenTiff: PTIFF;
FirstPageWidth,FirstPageHeight: Cardinal;
FirstPageBitmap: TBitmap;
begin
OpenTiff:=TIFFOpen('C:\World.tif','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]);
end;
但是为什么图片不显示?有人有解决办法吗?对不起我的英语不好。
使用下面的代码将 tiff 转换为位图。
然后照常显示位图。
这是您正在使用的完整函数(有一些改动)。
function ReadTiffIntoBitmap(const Filename: string): TBitmap;
var
OpenTiff: PTIFF;
FirstPageWidth, FirstPageHeight: Cardinal;
begin
Result:= nil; //in case you want to tweak code to not raise exceptions.
OpenTiff:= TIFFOpen(Filename,'r');
if OpenTiff = nil then raise Exception.Create(
'Unable to open file '''+Filename+'''');
try
TIFFGetField(OpenTiff, TIFFTAG_IMAGEWIDTH, @FirstPageWidth);
TIFFGetField(OpenTiff, TIFFTAG_IMAGELENGTH, @FirstPageHeight);
Result:= TBitmap.Create;
try
Result.PixelFormat:= pf32bit;
Result.Width:= FirstPageWidth;
Result.Height:= FirstPageHeight;
except
FreeAndNil(Result);
raise Exception.Create('Unable to create TBitmap buffer');
end;
TIFFReadRGBAImage(OpenTiff, FirstPageWidth, FirstPageHeight,
Result.Scanline[FirstPageHeight-1],0);
TIFFReadRGBAImageSwapRB(FirstPageWidth, FirstPageheight,
Result.Scanline[FirstPageHeight-1]);
finally
TIFFClose(OpenTiff);
end;
end;
现在在以下上下文中使用它:
在表单上放置一个按钮和一个图像。
双击按钮并填充按钮的 OnClick 处理程序,如下所示:
Form1.Button1Click(sender: TObject);
var
MyBitmap: TBitmap;
begin
MyBitmap:= ReadTiffIntoBitmap('c:\test.tiff');
try
//uncomment if..then if ReadTiffIntoBitmap does not raise exceptions
//but returns nil on error instead.
{if Assigned(MyBitmap) then} Image1.Picture.Assign(MyBitmap);
finally
MyBitmap.Free;
end;
end;
我在以下位置找到了您的代码段的完整版本:http://www.asmail.be/msg0055571626.html