【发布时间】:2010-12-01 05:37:34
【问题描述】:
使用 MagickWand API 从 PNG 转换为 JPG 时,如何将透明像素的背景设置为白色?
【问题讨论】:
使用 MagickWand API 从 PNG 转换为 JPG 时,如何将透明像素的背景设置为白色?
【问题讨论】:
if(current_wand && IsMagickWand(current_wand)){
status=MagickReadImage(current_wand, "test.png");
if (status == MagickFalse) {
ThrowWandException(current_wand);
}
PixelWand *color = NewPixelWand();
PixelSetColor(color, "white");
MagickSetImageBackgroundColor(current_wand, color);
MagickWand *newwand = MagickMergeImageLayers(current_wand, FlattenLayer);
MagickWriteImage(newwand, "test.jpg");
DestroyMagickWand(newwand);
}
【讨论】:
FlattenLayer 会导致生成的 JPG 对于某些 PNG 具有不同的图像尺寸(宽度或高度)。使用 MergeLayer 代替我解决了这个问题。
使用 MagickMergeImageLayers
【讨论】: