Author |
Topic |
|
jameszsc
USA
7 Posts |
Posted - Jul 27 2011 : 01:15:30
|
Hi all,
I am running into a problem with my scanned TIFF file, everything seems to be working fine, except that the file size is huge (30MB even for only one page). Has anyone had the same or similar issue, I am using Delphi 7, I am posting my code below. Thanks in advance!
James
+++++++++++++
function TSTSImageControl.Save(const FileName: WideString): WordBool; var i:integer; begin result:=false; try
ScannerSet.CompressionType:=4;
SaveImageBitmap; for i:=0 to ImageEnMView1.MIO.ParamsCount-1 do begin if uppercase(ExtractFileExt(FileName))='.TIF' then begin case ScannerSet.CompressionType of 0:ImageEnMView1.MIO.Params[i].TIFF_Compression:=ioTIFF_CCITT1D; 1:ImageEnMView1.MIO.Params[i].TIFF_Compression:=ioTIFF_G3FAX1D; 2:ImageEnMView1.MIO.Params[i].TIFF_Compression:=ioTIFF_G3FAX2D; 3:ImageEnMView1.MIO.Params[i].TIFF_Compression:=ioTIFF_G4FAX; 4:ImageEnMView1.MIO.Params[i].TIFF_Compression:=ioTIFF_JPEG; else ImageEnMView1.MIO.Params[i].TIFF_Compression:=ioTIFF_JPEG; end;
end else begin ImageEnMView1.MIO.Params[i].TIFF_Compression:=ioTIFF_JPEG; .MIO.Params[i].TIFF_JPEGQuality:=ScannerSet.JPEGQuality; end; ImageEnMView1.MIO.Params[i].DpiX:=ScannerSet.XImageResolution; ImageEnMView1.MIO.Params[i].DpiY:=ScannerSet.YImageResolution;
if (ImageEnMView1.MIO.Params[i].DpiX>0)and(ImageEnMView1.MIO.Params[i].DpiY>0) then begin ImageEnMView1.MIO.Params[i].Width:= round(ImageEnMView1.MIO.Params[i].DpiX*self.ScannerSet.ImageWidth*Const_InchCm); ImageEnMView1.MIO.Params[i].height:= round(ImageEnMView1.MIO.Params[i].DpiY*self.ScannerSet.ImageHeight*Const_InchCm); end else begin ImageEnMView1.MIO.Params[i].DpiX:=400; ImageEnMView1.MIO.Params[i].DpiY:=400; ImageEnMView1.MIO.Params[i].Width:= round(400*self.ScannerSet.ImageWidth*Const_InchCm); ImageEnMView1.MIO.Params[i].height:= round(400*self.ScannerSet.ImageHeight*Const_InchCm); end; end; ImageEnMView1.MIO.Update; .MIO.SaveToFile(FileName); ImageEnmview1.MIO.SaveToFileTIFF(FileName); except exit; end; result:=true; end; |
|
fab
1310 Posts |
Posted - Jul 27 2011 : 01:54:00
|
Hello, if you select ioTIFF_CCITT1D, ioTIFF_G3FAX1D, ioTIFF_G3FAX2D or ioTIFF_G4FAX make sure the bits per pixel and samples per pixel settings are "1" (1 bit, black/white). For example, you could write:
ImageEnMView1.MIO.Params[i].BitsPerSample := 1; ImageEnMView1.MIO.Params[i].SamplesPerPixel :=1;
Please note that:
ImageEnMView1.MIO.Params[i].Width:= ... ImageEnMView1.MIO.Params[i].height:= ...
have no-sense on saving. If you want to resize the image use another way. |
|
|
jameszsc
USA
7 Posts |
Posted - Jul 28 2011 : 00:54:59
|
thanks! but I need to get color Tiff file.and I have tried the ioTIFF_OLDJPEG,It is seems fine,file size is 1M for one page,Is it right? |
|
|
fab
1310 Posts |
Posted - Jul 28 2011 : 02:10:54
|
Please don't use ioTIFF_OLDJPEG. Instead use ioTIFF_JPEG, which is TIFF standard. |
|
|
jameszsc
USA
7 Posts |
Posted - Jul 28 2011 : 02:13:53
|
I have tried the ioTIFF_JPEG first time,this file size is too large.look at my code before please. |
|
|
fab
1310 Posts |
Posted - Jul 28 2011 : 02:34:01
|
Please re-test your code because the compression is the same, only the disposition of TIFF tags changes (ioTIFF_OLDJPEG now is non-standard) among ioTIFF_OLDJPEG and ioTIFF_JPEG. |
|
|
jameszsc
USA
7 Posts |
Posted - Jul 31 2011 : 23:51:06
|
hi, I have change my code ,the issues : 1.the TIF file size is 1M for one page,this still seems too large. 2.can view by 'Microsoft Office Document Imaging',but can not view by 'Windows Picture and fax viewer' please look at my code below,thanks for you help:
function TSTSImageControl.Save(const FileName: WideString): WordBool; var i:integer; begin result:=false; try SaveImageBitmap; for i:=0 to ImageEnMView1.MIO.ParamsCount-1 do begin ImageEnMView1.MIO.Params[i].TIFF_Compression:=ioTIFF_JPEG; end; ImageEnMView1.MIO.Update; ImageEnMView1.MIO.SaveToFile(FileName); except exit; end; result:=true; end; |
|
|
fab
1310 Posts |
Posted - Aug 01 2011 : 00:31:14
|
Hi, the code is correct, anyway you can also write:
function TSTSImageControl.Save(const FileName: WideString): WordBool;
var
i:integer;
begin
result:=false;
try
SaveImageBitmap;
ImageEnMView1.MIO.Params[0].TIFF_Compression:=ioTIFF_JPEG; // assume at least 1 image exists
ImageEnMView1.MIO.DuplicateCompressionInfo();
ImageEnMView1.MIO.SaveToFile(FileName);
except
exit;
end;
result := not ImageEnMView1.MIO.Aborting;
end;
>1.the TIF file size is 1M for one page,this still seems too large.
please send a sample file.
>2.can view by 'Microsoft Office Document Imaging',but can not view by 'Windows Picture and fax viewer'
I don't know. Maybe "Windows Picture and fax viewer" cannot read jpeg encoded TIFF files.
|
|
|
jameszsc
USA
7 Posts |
|
fab
1310 Posts |
Posted - Aug 01 2011 : 01:35:58
|
>1.tif file is here http://www.mz-intl.com/amy/work/A-2009-32-00016-SE96.TIF
It is normal to have a 2550x3509 image, saved in 1.25 MB file. Just save it as jpeg an you will have almost the same file size.
>2.I can open with a few different applications If used 'ioTIFF_G4FAX' >, except that the file size is huge (30MB even for only one page)
Just setting BitsPerSample=1 and SamplesPerPixel=1 (and ioTIFF_G4FAX) I get a file of size 68.6 Kbytes. Of course it is black/white (as explained in the first reply).
If you don't set BitsPerSample/SamplesPerPIxel the image is saved "uncompressed": its size will be 25MBytes.
|
|
|
jameszsc
USA
7 Posts |
Posted - Aug 01 2011 : 01:53:26
|
1.the requirement is 'need to save to TIF file' 2.Just setting BitsPerSample=1 and SamplesPerPixel=1 (and ioTIFF_G4FAX) I get a file of size 68.6 Kbytes. Of course it is black/white (as explained in the first reply).
yes , Just like you said ,but I need to get cololr TIF file.
thank you very much! |
|
|
fab
1310 Posts |
Posted - Aug 01 2011 : 02:17:45
|
>yes , Just like you said ,but I need to get cololr TIF file.
Hence you cannot use ioTIFF_CCITT1D, ioTIFF_G3FAX1D, ioTIFF_G3FAX2D and ioTIFF_G4FAX.
Use ioTIFF_JPEG (or ioTIFF_OLDJPEG if you prefer): the size you have got is ok. |
|
|
jameszsc
USA
7 Posts |
Posted - Aug 01 2011 : 02:29:27
|
I have tried ioTIFF_CCITT1D, ioTIFF_G3FAX1D, ioTIFF_G3FAX2D and ioTIFF_G4FAX.the file size are too large(20M),
Use ioTIFF_JPEG (or ioTIFF_OLDJPEG if you prefer): the size you have got is ok. but can not view with Windows Picture and fax viewer. |
|
|
fab
1310 Posts |
Posted - Aug 01 2011 : 02:33:20
|
ioTIFF_CCITT1D, ioTIFF_G3FAX1D, ioTIFF_G3FAX2D and ioTIFF_G4FAX are available only with black/white images. If you use one of these compressions with a color image then it is ignored (uncompressed).
|
|
|
|
Topic |
|