2

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?

Community
  • 1
  • 1
Oldes
  • 937
  • 1
  • 9
  • 24

1 Answers1

2

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);
}
Oldes
  • 937
  • 1
  • 9
  • 24
  • Are you able to lend a helping hand with the following question? http://stackoverflow.com/questions/7480812/iphone-imagemagick-library-converting-from-batch-file-script-to-objective-c-usi – gotnull Sep 21 '11 at 05:08