Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. create dimmed icon with magick++ (ImageMagick)

create dimmed icon with magick++ (ImageMagick)

Scheduled Pinned Locked Moved C / C++ / MFC
c++comjsontutorialquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Thue Andersen
    wrote on last edited by
    #1

    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

    C L 2 Replies Last reply
    0
    • T Thue Andersen

      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

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      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.

      image processing toolkits | batch image processing

      1 Reply Last reply
      0
      • T Thue Andersen

        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

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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

        T 1 Reply Last reply
        0
        • L Lost User

          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

          T Offline
          T Offline
          Thue Andersen
          wrote on last edited by
          #4

          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?

          R 1 Reply Last reply
          0
          • T Thue Andersen

            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?

            R Offline
            R Offline
            Rozis
            wrote on last edited by
            #5

            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?

            T 1 Reply Last reply
            0
            • R Rozis

              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?

              T Offline
              T Offline
              Thue Andersen
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups