Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load and display tiff images in TImage control?

I am currently working on Delphi XE2 trial version. I want to load and display TIFF images in TImage control without using any third party component/library.

I tried below code but it is not woking for me.

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;

Please advice.

like image 718
Dev Avatar asked Dec 09 '22 05:12

Dev


1 Answers

     tiff := TWICImage.Create;
     tiff.LoadFromFile(Filename);
     ABitmap.Assign(tiff);
like image 82
dwrbudr Avatar answered Jan 05 '23 20:01

dwrbudr