如何在MagickWand中设置透明像素的背景颜色?

时间:2008-12-16 21:44:57

标签: imagemagick magickwand

使用MagickWand API从PNG转换为JPG时,如何为透明像素将背景设置为白色?

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:1)

使用MagickMergeImageLayers