2005.01.23 16:43 "[Tiff] LibTiffDelphi", by Michel Salvagniac

2005.01.23 16:43 "[Tiff] LibTiffDelphi", by Michel Salvagniac

Hello,

I use this program: http://homepages.borland.com/efg2lab/ImageProcessing/pf1bit.htm to test LibTiffDelphi.

I've dropped a button on the form and added this code:

procedure TFormPf1bit.Button2Click(Sender: TObject);
var
imgtif:PTIFF;
x,y,hauteur,largeur:integer;
imgdata: pByteArray;
taille:integer;
begin
      hauteur := ImageBits.Picture.Bitmap.Height;
      largeur := ImageBits.Picture.Bitmap.Width;

      for y :=0 to hauteur - 1 do
        begin
        imgdata:= ImageBits.Picture.Bitmap.Scanline[y];
        end;

imgtif:=TIFFOpen('output.tif', 'w') ;
 TIFFSetField(imgtif, TIFFTAG_IMAGEWIDTH, largeur);
  TIFFSetField(imgtif, TIFFTAG_IMAGELENGTH, hauteur);
  TIFFSetField(imgtif, TIFFTAG_BITSPERSAMPLE, 1);
  TIFFSetField(imgtif, TIFFTAG_SAMPLESPERPIXEL, 1);
  TIFFSetField(imgtif, TIFFTAG_ROWSPERSTRIP, hauteur);

  TIFFSetField(imgtif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
  TIFFSetField(imgtif, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
  TIFFSetField(imgtif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);

  TIFFSetField(imgtif, TIFFTAG_XRESOLUTION, 150.0);
  TIFFSetField(imgtif, TIFFTAG_YRESOLUTION, 150.0);
  TIFFSetField(imgtif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
taille:=TIFFWriteRawStrip(imgtif, 0, imgdata, (largeur div 8) * hauteur);
Showmessage('taille écrite: '+ intToStr(taille));
TIFFClose(imgtif);
end;

The images are not created as expected, for example the "g" is inverted. The resolution is not taken

tiffinfo says:
TIFF Directory at offset 0x88
  Image Width: 32 Image Length: 32
  Resolution: 0, 0 pixels/inch
  Bits/Sample: 1
  Compression Scheme: None
  Photometric Interpretation: min-is-white
  FillOrder: msb-to-lsb
  Samples/Pixel: 1
  Rows/Strip: 32
  Planar Configuration: single image plane.

If i try

  TIFFSetField(imgtif, TIFFTAG_XRESOLUTION, 200.0);
  TIFFSetField(imgtif, TIFFTAG_YRESOLUTION, 200.0);

I get a "floating point error"

Thank you for the answer(s)

Michel