create dimmed icon with magick++ (ImageMagick)
-
I’m trying to use ImageMagick for what I believed would be a simple task. I want to generate a dimmed version of an image/icon at runtime in the application. I use the magick++ c plus api. I have found some commands that give me an ok result when run from the command line. Converting the commands to the c++ api was a bit challenging, and the result is then not as hoped. // Command example convert -size 32x32 xc:"#999999" gray32.png composite -dissolve 50% logo32.png gray32.png dim_logo32.png How would this look in c++? I came up with this.
Magick::Image gray; gray.size( Magick::Geometry(image.columns(), image.rows())); gray.read( "xc:#999999"); gray.label( "gray" ); if(gray.isValid()) { gray.opacity(QuantumRange/2); image.composite(gray, Magick::Geometry(image.columns(),image.rows()), Magick::DissolveCompositeOp );
But the transparency in the picture is lost. A other suggestion as to make a dimmed image, is to make the full image semi transparent. convert input.png -channel Alpha -evaluate Set 50% output.png This could work. The transparency is kept when I tried this from command line. Changing this to c++ api confused me a lot. I ended up with this single line. image.opacity(QuantumRange/ 2); Now the result from this confuses me. The image is semi transparent, but the background that was originally transparent is now magenta. orginal icon
dimmed icon
-
I’m trying to use ImageMagick for what I believed would be a simple task. I want to generate a dimmed version of an image/icon at runtime in the application. I use the magick++ c plus api. I have found some commands that give me an ok result when run from the command line. Converting the commands to the c++ api was a bit challenging, and the result is then not as hoped. // Command example convert -size 32x32 xc:"#999999" gray32.png composite -dissolve 50% logo32.png gray32.png dim_logo32.png How would this look in c++? I came up with this.
Magick::Image gray; gray.size( Magick::Geometry(image.columns(), image.rows())); gray.read( "xc:#999999"); gray.label( "gray" ); if(gray.isValid()) { gray.opacity(QuantumRange/2); image.composite(gray, Magick::Geometry(image.columns(),image.rows()), Magick::DissolveCompositeOp );
But the transparency in the picture is lost. A other suggestion as to make a dimmed image, is to make the full image semi transparent. convert input.png -channel Alpha -evaluate Set 50% output.png This could work. The transparency is kept when I tried this from command line. Changing this to c++ api confused me a lot. I ended up with this single line. image.opacity(QuantumRange/ 2); Now the result from this confuses me. The image is semi transparent, but the background that was originally transparent is now magenta. orginal icon
dimmed icon
Thue Andersen wrote:
Now the result from this confuses me. The image is semi transparent, but the background that was originally transparent is now magenta.
i suspect you've set the entire alpha channel to 128, not just reduced the exiting alpha by 1/2.
-
I’m trying to use ImageMagick for what I believed would be a simple task. I want to generate a dimmed version of an image/icon at runtime in the application. I use the magick++ c plus api. I have found some commands that give me an ok result when run from the command line. Converting the commands to the c++ api was a bit challenging, and the result is then not as hoped. // Command example convert -size 32x32 xc:"#999999" gray32.png composite -dissolve 50% logo32.png gray32.png dim_logo32.png How would this look in c++? I came up with this.
Magick::Image gray; gray.size( Magick::Geometry(image.columns(), image.rows())); gray.read( "xc:#999999"); gray.label( "gray" ); if(gray.isValid()) { gray.opacity(QuantumRange/2); image.composite(gray, Magick::Geometry(image.columns(),image.rows()), Magick::DissolveCompositeOp );
But the transparency in the picture is lost. A other suggestion as to make a dimmed image, is to make the full image semi transparent. convert input.png -channel Alpha -evaluate Set 50% output.png This could work. The transparency is kept when I tried this from command line. Changing this to c++ api confused me a lot. I ended up with this single line. image.opacity(QuantumRange/ 2); Now the result from this confuses me. The image is semi transparent, but the background that was originally transparent is now magenta. orginal icon
dimmed icon
Aside from the transperency in the alpha channel, one pixel value can be chosen as fully transparent. This is often chosen to be magenta (R=255, G=0, B=255, A=255). Now that you have modified the alpha component of every pixel, what was previously (R=255, G=0, B=255, A=255), is now (R=255, G=0, B=255, A=128). It's no longer recognised as fully transparent and instead treated as magenta at half transperency. So to solve your problem, you'd have to either exclude the magenta (R=255, G=0, B=255, A=255) pixels from having their transperency halved or change the transparent pixel value to be (R=255, G=0, B=255, A=128).
modified on Friday, January 14, 2011 6:04 PM
-
Aside from the transperency in the alpha channel, one pixel value can be chosen as fully transparent. This is often chosen to be magenta (R=255, G=0, B=255, A=255). Now that you have modified the alpha component of every pixel, what was previously (R=255, G=0, B=255, A=255), is now (R=255, G=0, B=255, A=128). It's no longer recognised as fully transparent and instead treated as magenta at half transperency. So to solve your problem, you'd have to either exclude the magenta (R=255, G=0, B=255, A=255) pixels from having their transperency halved or change the transparent pixel value to be (R=255, G=0, B=255, A=128).
modified on Friday, January 14, 2011 6:04 PM
So imagemagick internally uses magenta as transparent colour? And when I changed the opacity of the whole image it also applied this for the transparent colour. The two suggested solutions sound interesting, I have tried to implement solution two.
image.opacity(MaxRGB / 2); Magick::Color color(MaxRGB, 0, MaxRGB, MaxRGB / 2); image.transparent(color);
But why is this exstra step necessary? In the command line we just set 50% alpha and done. Would there be a better solution to create a dimmed icon?
-
So imagemagick internally uses magenta as transparent colour? And when I changed the opacity of the whole image it also applied this for the transparent colour. The two suggested solutions sound interesting, I have tried to implement solution two.
image.opacity(MaxRGB / 2); Magick::Color color(MaxRGB, 0, MaxRGB, MaxRGB / 2); image.transparent(color);
But why is this exstra step necessary? In the command line we just set 50% alpha and done. Would there be a better solution to create a dimmed icon?
Not an answer to your question, but what i don't understand is: Why not render the dimmed icon offline (with the commandline) and read this icon in, during runtime? I guess you don't create icons in runtime on the fly, so what is the use to create a dimmed version in runtime?
-
Not an answer to your question, but what i don't understand is: Why not render the dimmed icon offline (with the commandline) and read this icon in, during runtime? I guess you don't create icons in runtime on the fly, so what is the use to create a dimmed version in runtime?
Because the icons are defined by the end-user. The system allows end-user to save his own icons into the database. To simplify this task he only has to provide one version of the icon, and we will generate the dimmed version automatically.