尝试使用 CCITT 组 4 压缩将 24 bpp 位图转换为黑白 TIFF。结果是预期的 TIFF 1 bpp 图像,但未压缩。
我正在使用具有 magickwand 绑定的 FreePascal,并且状态永远不会是 MagickFalse:
MagickWandGenesis;
wand := NewMagickWand;
try
status := MagickReadImage(wand,PChar(InputFile));
if (status = MagickFalse) then HandleError;
status := MagickSetImageFormat(wand,'TIFF');
if (status = MagickFalse) then HandleError;
// convert to black & white/lineart
status := MagickSetImageType(wand,BilevelType);
if (status = MagickFalse) then HandleError;
// Group4Compression seems defined as 4 which
// apparently doesn't match imagemagick source. Bug:
//http://mantis.freepascal.org/view.php?id=26723
status := MagickSetImageCompression(wand,CompressionType(7)); //was Group4Compression
if (status = MagickFalse) then HandleError;
// Apparently set(image)compresionquality and
// stripimage are necessary to actually compress
status := MagickSetImageCompressionQuality(wand,0);
if (status = MagickFalse) then HandleError;
status := MagickStripImage(wand);
if (status = MagickFalse) then HandleError;
status := MagickWriteImage(wand,PChar(OutputFile));
if (status = MagickFalse) then HandleError;
finally
wand := DestroyMagickWand(wand);
end;
MagickWandTerminus;
http://filehorst.de/d/bmqjzDuB上的源图像
原始(错误)程序源代码位于http://filehorst.de/d/bluhjivq
http://filehorst.de/d/bhlbjHgp上的原始(错误)输出图像
我究竟做错了什么?
编辑:已解决;在异地获得解决方案:FreePascal 绑定中的 CompressionType 枚举可能已过时 - Group4Compression 为 4 (IIRC),而应该为 7。
我将赏金给 Mark Setchell,因为他的回答是解决方案的必要部分。上面的源代码更新为正确的版本。