我目前正在使用Delphi XE2试用版。我想在TImage控件中加载和显示TIFF图像,而无需使用任何第三方组件/库。如何在TImage控件中加载和显示tiff图像?
我想下面的代码,但它不是沃金给我。
Procedure TForm1.Button1Click(Sender: TObject);
Var
OleGraphic : TOleGraphic;
fs : TFileStream;
Source : TImage;
BMP : TBitmap;
Begin
Try
OleGraphic := TOleGraphic.Create;
fs := TFileStream.Create('c:\testtiff.dat', fmOpenRead Or fmSharedenyNone);
OleGraphic.LoadFromStream(fs);
Source := Timage.Create(Nil);
Source.Picture.Assign(OleGraphic);
BMP := TBitmap.Create;
bmp.Width := Source.Picture.Width;
bmp.Height := source.Picture.Height;
bmp.Canvas.Draw(0, 0, source.Picture.Graphic);
image1.Picture.Bitmap := bmp;
Finally
fs.Free;
OleGraphic.Free;
Source.Free;
bmp.Free;
End;
End;
请指教。
如果文件扩展名是一个标准的TIFF扩展,这将是一个班轮,image1.Picture.LoadFromFile(MyTiffFile)。否则,这个SO问题可能会帮助你[如何加载任意图像从一个blob流到一个图像](http://stackoverflow.com/questions/6251504/how-加载任意图像从blob流到一个图像) –
我不知道这段代码是否来自http://www.swissdelphicenter.ch/en/showcode.php中的示例?id = 2012(2004年)。我只是在我工作的代码库的一个很少探索的部分中找到了相同的代码。 –