Page 1 of 1

Transparent SVG part rendered as white background

Posted: 2014-03-04T08:07:18-07:00
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

Re: Transparent SVG part rendered as white background

Posted: 2014-03-05T07:23:42-07:00
by dmaciejak
MagickSetBackgroundColor() has to be called before the MagickReadImage()