How to set background color for transparent pixels in MagickWand?

你说的曾经没有我的故事 提交于 2019-12-11 05:03:23

问题


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


回答1:


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



回答2:


Use MagickMergeImageLayers



来源:https://stackoverflow.com/questions/372872/how-to-set-background-color-for-transparent-pixels-in-magickwand

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!