Forum > Graphics

TImage and TIFF files

(1/1)

davect:
I was under the impression that TImage support the use of TIFF files. Am I mistaken? Neither of the following work.


--- Code: ---image1.Picture.LoadFromFile (sFilename);
--- End code ---
results in the error message "Unknown picture extension."


--- Code: ---image1.Picture.bitmap.LoadFromFile (sFilename);
--- End code ---
results in the error message "wrong image format".

Leledumbo:

--- Quote ---I was under the impression that TImage support the use of TIFF files. Am I mistaken?
--- End quote ---
AFAIK, yes you are. Just check the documentation of TPicture, all supported image formats must be loadable by it (CMIIW).

theo:
There are readers and writers for TIFF in the fcl.
I don't know how good they are. Reading all sorts of Tiff subformats is nearly impossible without LibTiff afaik.

However this seems to work (needs any image in Image1):


--- Code: ---uses .. IntfGraphics, FPReadTiff, FPWriteTiff;

procedure TForm1.Button1Click(Sender: TObject);
var img:TLazIntfImage;
wt:TFPWriterTiff;
rt:TFPReaderTiff;
begin
wt:=TFPWriterTiff.Create;
img:=Image1.Picture.Bitmap.CreateIntfImage;
img.SaveToFile('ltest.tiff',wt);
img.free;
wt.free;

img:=TLazIntfImage.Create(0,0);
img.DataDescription:=GetDescriptionFromDevice(0);
rt:=TFPReaderTiff.create;
img.LoadFromFile('ltest.tiff',rt);
Image2.Picture.Bitmap.LoadFromIntfImage(img);
rt.free;
img.free;
end;         
--- End code ---

I don't know if this is the recommended way of doing it.
Lazarus / Freepascal Graphics is a bit of a mistery to me. ;-)
Maybe Marc can explain.

Marc:
We indeed don't have a TTiffImage yet. Adding it wouldn't be a big problem I think.

the way you load the image is more or less the same as TFPImageBitmap.ReadStream (fpimagebitmap.inc:125)


--- Code: ---    // read image
    ImgReader := GetReaderClass.Create;
    IntfImg := TLazIntfImage.Create(0,0,[]);
    InitializeReader(IntfImg, ImgReader);
    if Supports(ImgReader, ILazImageReader, LazReader)
    then LazReader.UpdateDescription := True
    else IntfImg.DataDescription := GetDescriptionFromDevice(0, 0, 0); // fallback to default
    ImgReader.ImageRead(AStream, IntfImg);
    FinalizeReader(ImgReader);

--- End code ---

Navigation

[0] Message Index

Go to full version