AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
February 2007

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



Thread

2007.02.06 03:31 "What's wrong with this program about adding a bitmap to TIFF file as Compression_JPEG ?", by <zhaoyj.flc@163.com>
2007.02.06 03:55 "What is wrong with the program about adding a Bitmap to a Tiff as Compression_JPEG ?", by <zhaoyj.flc@163.com>
2007.02.06 04:18 "Re: What is wrong with the program about adding a Bitmap to a Tiff as Compression_JPEG ?", by Joris Van Damme
2007.02.06 04:04 "Re: What's wrong with this program about adding a bitmap to TIFF file as Compression_JPEG ?", by Joris Van Damme

2007.02.06 03:55 "What is wrong with the program about adding a Bitmap to a Tiff as Compression_JPEG ?", by <zhaoyj.flc@163.com>

why was my later ignored ? Hi,All Heros: recently,I have some problems when
I program Delphi code to add a bitmap to TIFF file as Compression_JPEG ,The
Image Viewer of windows can't output the Image. The code like this: uses
LibTiffDelphi,ZLibDelphi,LibJpegDelphi,LibDelphi; procedure
AddBitmapAsJpegtoTiff; var OpenTiff: PTIFF; RowsPerStrip: Longword;
StripMemory: Pointer; StripIndex: Longword; StripRowOffset: Longword;
StripRowCount: Longword; ma,mb: PByte; nx,ny: Longword; Bitmap: Tbitmap;
begin Bitmap := Tbitmap.Create; Bitmap.LoadFromFile('0000.bmp'); if
(Bitmap.PixelFormat<>pf24bit) and (Bitmap.PixelFormat<>pf32bit) then exit;
RowsPerStrip:=((256*1024) div (Bitmap.Width*3)); if
RowsPerStrip>Bitmap.Height then RowsPerStrip:=Bitmap.Height else if
RowsPerStrip=0 then RowsPerStrip:=1;
StripMemory:=GetMemory(RowsPerStrip*Bitmap.Width*3);
OpenTiff:=TIFFOpen(PAnsiChar('jpegtiff.tif'),'w'); if OpenTiff=nil then
begin FreeMemory(StripMemory); exit; end;
TIFFSetField(OpenTiff,TIFFTAG_IMAGEWIDTH,Bitmap.Width);
TIFFSetField(OpenTiff,TIFFTAG_IMAGELENGTH,Bitmap.Height);
TIFFSetField(OpenTiff,TIFFTAG_BITSPERSAMPLE,8);
TIFFSetField(OpenTiff,TIFFTAG_COMPRESSION,COMPRESSION_JPEG);
TIFFSetField(OpenTiff,TIFFTAG_PHOTOMETRIC,PHOTOMETRIC_RGB);
TIFFSetField(OpenTiff,TIFFTAG_SAMPLESPERPIXEL,3);
TIFFSetField(OpenTiff,TIFFTAG_ROWSPERSTRIP,RowsPerStrip);
TIFFSetField(OpenTiff,TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG);
StripIndex:=0; StripRowOffset:=0; while
StripRowOffsetBitmap.Height-StripRowOffset then
StripRowCount:=Bitmap.Height-StripRowOffset; if Bitmap.PixelFormat=pf24bit
then begin mb:=StripMemory; for ny:=StripRowOffset to
StripRowOffset+StripRowCount-1 do begin ma:=Bitmap.ScanLine[ny]; for nx:=0
to Bitmap.Width-1 do begin mb^:=PByte(Cardinal(ma)+2)^; Inc(mb);
mb^:=PByte(Cardinal(ma)+1)^; Inc(mb); mb^:=PByte(Cardinal(ma)+0)^; Inc(mb);
Inc(ma,3); end; end; end else begin mb:=StripMemory; for ny:=StripRowOffset
to StripRowOffset+StripRowCount-1 do begin ma:=Bitmap.ScanLine[ny]; for
nx:=0 to Bitmap.Width-1 do begin mb^:=PByte(Cardinal(ma)+2)^; Inc(mb);
mb^:=PByte(Cardinal(ma)+1)^; Inc(mb); mb^:=PByte(Cardinal(ma)+0)^; Inc(mb);
Inc(ma,4); end; end; end; if TIFFWriteEncodedStrip(OpenTiff,StripIndex,
StripMemory,StripRowCount*Bitmap.Width*3)=0 then begin TIFFClose(OpenTiff);
FreeMemory(StripMemory); exit; end; Inc(StripIndex);
Inc(StripRowOffset,StripRowCount); end; TIFFClose(OpenTiff);
FreeMem(StripMemory); end; we can't watch The tiff'Image. This code also has
a problem, RowsPerStrip:=((256*1024) div (Bitmap.Width*3)); if 256*1024
become a large number,there will be more than one strip in the IFD,but the
data can't write ,only 1 KB after writing to the TIFF . How can I deal with
these problems? How to add two bitmaps to one TIFF ,also as Compression_JPEG
? Thanks before ! Zhaoyj