Transparent SVG part rendered as white background

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
dmaciejak
Posts: 4
Joined: 2014-03-04T07:59:13-07:00
Authentication code: 6789

Transparent SVG part rendered as white background

Post by dmaciejak »

Hi,

I am trying to read SVG images using ImageMagick (6.8.8-7) and get valid transparent pixels.

The code below is working well with PNG format, but for SVG i can only have some white background. So i tried to add MagickSetBackgroundColor, and MagickSetImageBackgroundColor with some merging layers but i still can't make it works.

Below an extract from the PoC:

Code: Select all


MagickWandGenesis();
m_wand = NewMagickWand();

MagickReadImage(m_wand, file_name);
	
hasAlfa = MagickGetImageAlphaChannel(m_wand);
fprintf(stderr, "alpha channel detection: %d\n", hasAlfa);

if (hasAlfa == MagickTrue) {

    PixelWand *color;
    MagickWand *new_wand;

    imagedata = malloc(w*h*4);

    color = NewPixelWand();
    PixelSetColor(color, "none");
    MagickSetBackgroundColor(m_wand, color);

    MagickSetImageBackgroundColor(m_wand, color);
    new_wand = MagickMergeImageLayers(m_wand, MergeLayer);
    DestroyMagickWand(m_wand);
    m_wand = new_wand;

    mrc = MagickExportImagePixels(m_wand, 0, 0, (size_t)w, (size_t)h, "RGBA", CharPixel, imagedata);

    fprintf(stderr, "R:%d G:%d B:%d A:%d\nR:%d G:%d B:%d A:%d\n", imagedata[0], imagedata[1], imagedata[2], imagedata[3], imagedata[4], imagedata[5], imagedata[6], imagedata[7]);
}
Result using a PNG image:

Code: Select all

size: 9 x 11
alpha channel detection: 1
R:0 G:0 B:0 A:0
R:0 G:0 B:0 A:0
Result using a SVG image:

Code: Select all

size: 640 x 1000
alpha channel detection: 1
R:255 G:255 B:255 A:255
R:255 G:255 B:255 A:255
Any clues ?

thanks,
david
dmaciejak
Posts: 4
Joined: 2014-03-04T07:59:13-07:00
Authentication code: 6789

Re: Transparent SVG part rendered as white background

Post by dmaciejak »

MagickSetBackgroundColor() has to be called before the MagickReadImage()
Post Reply