如何使用 Delphi 扫描 300dpi 图像并以 TIFF 格式保存?
我正在使用 Delphitwain (delphitwain.sourceforge.net) 向我的应用程序添加扫描功能。扫描工作正常,我可以保存 bmp 和 jpeg 文件。现在我需要:
- 以 300dpi 保存(扫描仪可以)
- 以 TIFF 格式保存
经过深入研究,我发现了 2 个提示:
http://www.delphipraxis.net/132787-farbstich-nach-bitmap-operation.html
http://synopse.info/fossil/wiki?name=GDI%2B
这是我的最终代码:
procedure TForm1.GoAcquireClick(Sender: TObject);
begin
Counter := 0;
Twain.SourceManagerLoaded := TRUE;
Twain.LoadSourceManager;
Twain.TransferMode := ttmMemory;
with Twain.Source[ 0 ] do
begin
Loaded := TRUE;
SetIXResolution(300);
SetIYResolution(300);
SetIBitDepth(1);
EnableSource(true, true);
while Enabled do Application.ProcessMessages;
end;
end;
procedure TForm1.TwainTwainAcquire(Sender: TObject; const Index: Integer;
Image: TBitmap; var Cancel: Boolean);
var
TiffHolder: TSynPicture;
begin
Inc( Counter );
Current := Counter;
ImageHolder.Picture.Assign( Image );
ImageHolder.Picture.Bitmap.Monochrome := true;
ImageHolder.Picture.Bitmap.Pixelformat := pf1Bit;
SynGDIPlus.SaveAs(ImageHolder.Picture, format('c:\temp\teste%d.tif',[ Counter ]), gptTIF );
end;
结果:图像仍然是 96dpi 并保存为 BMP(即使具有 TIF 扩展名)。
我缺少什么?
I'm using Delphitwain (delphitwain.sourceforge.net) to add scan functionality to my app. Scanning is working fine and I can save bmp and jpeg files. Now I need to:
- save in 300dpi (the scanner is capable)
- save in TIFF format
After digging around, I found 2 tips:
http://www.delphipraxis.net/132787-farbstich-nach-bitmap-operation.html
http://synopse.info/fossil/wiki?name=GDI%2B
Here is my final code:
procedure TForm1.GoAcquireClick(Sender: TObject);
begin
Counter := 0;
Twain.SourceManagerLoaded := TRUE;
Twain.LoadSourceManager;
Twain.TransferMode := ttmMemory;
with Twain.Source[ 0 ] do
begin
Loaded := TRUE;
SetIXResolution(300);
SetIYResolution(300);
SetIBitDepth(1);
EnableSource(true, true);
while Enabled do Application.ProcessMessages;
end;
end;
procedure TForm1.TwainTwainAcquire(Sender: TObject; const Index: Integer;
Image: TBitmap; var Cancel: Boolean);
var
TiffHolder: TSynPicture;
begin
Inc( Counter );
Current := Counter;
ImageHolder.Picture.Assign( Image );
ImageHolder.Picture.Bitmap.Monochrome := true;
ImageHolder.Picture.Bitmap.Pixelformat := pf1Bit;
SynGDIPlus.SaveAs(ImageHolder.Picture, format('c:\temp\teste%d.tif',[ Counter ]), gptTIF );
end;
Result: the image still is 96dpi and were saved as BMP (even with TIF extension).
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
GDI+库能够保存tiff图片。
SynGdiPlus 单元使用 {557CF405-1A04-11D3-9A73-0000F81EF32E} 作为其 TIFF 编码器。
从
TSynPicture.SaveAs
代码中,我看到两种可能性:尝试此版本:
它将为 TIFF 图片添加
EncoderCompression
参数,似乎是必需的。我已经更新了源代码存储库版本以包含此更正。
The GDI+ library is able to save tiff pictures.
The SynGdiPlus unit use {557CF405-1A04-11D3-9A73-0000F81EF32E} for its TIFF encoder.
From the
TSynPicture.SaveAs
code, I see two possibilities:Try this version:
It will add the
EncoderCompression
parameter for TIFF pictures, which seems to be required.I've updated the source code repository version to include this correction.
在 Delphi 中保存 TIFF 文件很困难。我不知道有任何免费/开源模块可以做到这一点。
ImageEn 有效。
过去,我使用命令行保存为 bmp 并通过 createprocess 使用 irfanview 转换为 tiff
'i_view32.exe c:\temp\scanned.bmp /bpp=1 /convert=c:\temp\scanned.tif'
Saving TIFF files is hard in Delphi. I don't know any free/open source modules that do this.
ImageEn works.
In the past I have used saving as bmp and converting to tiff with irfanview through createprocess with the commandline
'i_view32.exe c:\temp\scanned.bmp /bpp=1 /convert=c:\temp\scanned.tif'