How can I set the background color for transparent pixels in MagickWand?

When converting from PNG to JPG using the MagickWand API, how do I set transparent pixels to white?

+1


source to share


2 answers


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

      



+3


source


Use MagickMergeImageLayers



+1


source







All Articles