[Magick++] pixelColor() transparency problem
Posted: 2010-01-23T05:59:08-07:00
Hi everybody !
I am developping an application in C++ using Magick++ library. Basically, I would like to generate a black PNG file, with different trasparency levels depending on the pixel.
To do that, I compute for each pixel the value of the transparency chanel and I use the method pixelColor() on my image to set the color of each pixel.
In the Magick++ tutorial, the usage of this method is explained this way :
Now, there is my code :
You just have to know that the float value d computed is in [0.0, 1.0]. This code produces a black image with no transparency. My d values are well computed : when I change the line
to :
I obtain a greyscale image, in which I would like to set light pixels transparent.
It's been two days I am looking for an answer... No result... I really count on you !
I am developping an application in C++ using Magick++ library. Basically, I would like to generate a black PNG file, with different trasparency levels depending on the pixel.
To do that, I compute for each pixel the value of the transparency chanel and I use the method pixelColor() on my image to set the color of each pixel.
In the Magick++ tutorial, the usage of this method is explained this way :
Code: Select all
// Example: setting pixels
Image my_image("640x480", "white"); // start with creating a white-background canvas
my_image.pixelColor(50,50,Color("red")); // set the pixel at position (50,50) to red
my_image.pixelColor(5,5,Color(MaxRGB,0,0,MaxRGB/2)); // set semitransparent red at (5,5)
Code: Select all
int main()
{
Image img = Image(Geometry(1000, 1000), "white");
for (int i = 0; i < 1000; i++)
{
for (int j = 0; j < 1000; j++)
{
float d;
if ((i/500)%2 == 0)
{
if ((j/500)%2 == 0) d = PerlinNoise_2D((i%500)/100.0, (j%500)/100.0);
else d = PerlinNoise_2D((i%500)/100.0, (500-(j%500))/100.0);
}
else
{
if ((j/500)%2 == 0) d = PerlinNoise_2D((500-(i%500))/100.0, (j%500)/100.0);
else d = PerlinNoise_2D((500-(i%500))/100.0, (500-(j%500))/100.0);
}
d = (d+1.0)/2.0;
int res = (int) (d * MaxRGB);
img.pixelColor(i, j, Color(0.0, 0.0, 0.0, res));
}
}
img.write("tst.png");
return 0;
}
Code: Select all
img.pixelColor(i, j, Color(0.0, 0.0, 0.0, res));
Code: Select all
img.pixelColor(i, j, Color(res, res, res, MaxRGB));
It's been two days I am looking for an answer... No result... I really count on you !