尝试将24 bpp位图转换为black&具有CCITT组4压缩的白色TIFF。结果是TIFF 1 bpp图像,正如预期的那样,但它是未压缩的。
我使用的是FreePascal,它有magicband绑定,状态从来都不是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赏金,因为他的回答是解决方案的必要组成部分。上面的源代码更新为正确的版本。
至少在PHP版本中,设置压缩类型似乎并不能真正压缩图像-请参阅底部的注释。
它还显示,在我发现的所有示例中,您必须随后调用MagickSetImageCompressionQuality()
和StripImage()
才能实际执行压缩-请参阅此处。