Gburd
Gburd

Reputation:

How to set background color for transparent pixels in MagickWand?

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

Upvotes: 1

Views: 2094

Answers (2)

Oldes
Oldes

Reputation: 989

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

Upvotes: 3

Gburd
Gburd

Reputation:

Use MagickMergeImageLayers

Upvotes: 1

Related Questions