2012.09.11 13:58 "[Tiff] Delphi and WindowsXP problems", by Martin

2012.09.11 13:58 "[Tiff] Delphi and WindowsXP problems", by Martin

Hi,

I use LibTiffDelphi to make a simple TIFF image (1bit only black and
white color).
My problem is this: on my windows 7 all works, I get a image with white
background and black lines (I draw some lines on TIFF).
On windows XP I get always black background and white lines...
I use always the some code:

procedure TMyForm.WriteBitmapToTiff(Bitmap: TBitmap; Filename: String);
var
   OpenTiff: PTIFF;
   RowSize: Longword;
   RowsPerStrip: Longword;
   StripMemory: Pointer;
   StripIndex: Longword;
   StripRowOffset: Longword;
   StripRowCount: Longword;
   mb: PByte;
   ny: Longword;
   dpi: Double;
begin
   Bitmap.PixelFormat:=pf1bit;
   RowSize:=((Bitmap.Width+7) div 8);
   RowsPerStrip:=((256*1024) div RowSize);
   if RowsPerStrip>Bitmap.Height then
     RowsPerStrip:=Bitmap.Height
   else if RowsPerStrip=0 then
     RowsPerStrip:=1;

StripMemory:=GetMemory(RowsPerStrip*RowSize); OpenTiff:=TIFFOpen(PAnsiChar(Filename),'w');

if OpenTiff=nil then
begin
  FreeMemory(StripMemory);
  raise Exception.Create('Unable to create file '''+Filename+'''');
end;

TIFFSetField(OpenTiff,TIFFTAG_IMAGEWIDTH,Bitmap.Width);

TIFFSetField(OpenTiff,TIFFTAG_IMAGELENGTH,Bitmap.Height);

TIFFSetField(OpenTiff,TIFFTAG_PHOTOMETRIC,PHOTOMETRIC_MINISBLACK);

TIFFSetField(OpenTiff,TIFFTAG_SAMPLESPERPIXEL,1);

TIFFSetField(OpenTiff,TIFFTAG_BITSPERSAMPLE,1);

TIFFSetField(OpenTiff,TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG);

TIFFSetField(OpenTiff,TIFFTAG_COMPRESSION,COMPRESSION_CCITTFAX4); // deve essere un double, se si usa un integer non funziona dpi := 200; TIFFSetField(OpenTiff,TIFFTAG_XRESOLUTION, dpi);

TIFFSetField(OpenTiff,TIFFTAG_YRESOLUTION, dpi);

TIFFSetField(OpenTiff,TIFFTAG_RESOLUTIONUNIT,RESUNIT_INCH);

TIFFSetField(OpenTiff,TIFFTAG_ROWSPERSTRIP,RowsPerStrip);

   StripIndex:=0;
   StripRowOffset:=0;
   while StripRowOffset<Bitmap.Height do
   begin
     StripRowCount:=RowsPerStrip;
     if StripRowCount>Bitmap.Height-StripRowOffset then
       StripRowCount:=Bitmap.Height-StripRowOffset;
     mb:=StripMemory;
     for ny:=StripRowOffset to StripRowOffset+StripRowCount-1 do
     begin
       CopyMemory(mb,Bitmap.ScanLine[ny],RowSize);
       Inc(mb,RowSize);
     end;
     if TIFFWriteEncodedStrip(OpenTiff,StripIndex,
         StripMemory,StripRowCount*RowSize)=-1 then
     begin
       TIFFClose(OpenTiff);
       FreeMemory(StripMemory);
       raise Exception.Create('Failed to write '''+Filename+'''');
     end;
     Inc(StripIndex);
     Inc(StripRowOffset,StripRowCount);
   end;
   TIFFClose(OpenTiff);
   FreeMem(StripMemory);
end;

Can you help me to understand the problem?