开发者

magickWand -> PNG to JPG

开发者 https://www.devze.com 2023-01-28 03:33 出处:网络
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.

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消