magickWand -> PNG to JPG
When converting from PNG to JPG using the MagickWand API, how do I set the background to specified color for transparent pixels? I still get only white background which I don't want.
I know there 开发者_如何学运维is similar question, but without answer = How to set background color for transparent pixels in MagickWand?
I've found it... I missed that MagickMergeImageLayers is returning new wand! So the code looks like:
if(current_wand && IsMagickWand(current_wand)){
status=MagickReadImage(current_wand, "test.png");
if (status == MagickFalse) {
ThrowWandException(current_wand);
}
PixelWand *color = NewPixelWand();
PixelSetColor(color, "red");
MagickSetImageBackgroundColor(current_wand, color);
MagickWand *newwand = MagickMergeImageLayers(current_wand, FlattenLayer);
MagickWriteImage(newwand, "test.jpg");
DestroyMagickWand(newwand);
}
精彩评论