2007.02.05 03:28 "[Tiff] Request help On OJPEG Compression In Libtiff", by Steven Lim

2007.02.06 03:55 "[Tiff] What is wrong with the program about adding a Bitmap to a Tiff as Compression_JPEG ?", by 赵

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