When converting from PNG to JPG using the MagickWand API, how do I set the background to white for transparent pixels?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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);
}
回答2:
Use MagickMergeImageLayers