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. Drawing a grayscale Icon

Drawing a grayscale Icon

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestionannouncement
5 Posts 3 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.
  • _ Offline
    _ Offline
    __DanC__
    wrote on last edited by
    #1

    I am trying to create a grayscale version of an icon. I have extracted the icon and have an HICON but how would I create a grayscale version? I have been trying to figure it out and it seems I need to create an HDC and draw the icon into that but I am new to graphics and am a bit lost...

    K M 3 Replies Last reply
    0
    • _ __DanC__

      I am trying to create a grayscale version of an icon. I have extracted the icon and have an HICON but how would I create a grayscale version? I have been trying to figure it out and it seems I need to create an HDC and draw the icon into that but I am new to graphics and am a bit lost...

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      hIconGrey = ::CopyImage( hIcon, IMAGE_ICON, 32, 32, LR_MONOCHROME ); too easy too find it :doh:

      Greetings from Germany

      _ 1 Reply Last reply
      0
      • K KarstenK

        hIconGrey = ::CopyImage( hIcon, IMAGE_ICON, 32, 32, LR_MONOCHROME ); too easy too find it :doh:

        Greetings from Germany

        _ Offline
        _ Offline
        __DanC__
        wrote on last edited by
        #3

        Thanks for the reply but I have tried that and the image comes out just black and white, I need grayscale so the image looks like the original but no colour. Is there a way I can do that using that function?

        1 Reply Last reply
        0
        • _ __DanC__

          I am trying to create a grayscale version of an icon. I have extracted the icon and have an HICON but how would I create a grayscale version? I have been trying to figure it out and it seems I need to create an HDC and draw the icon into that but I am new to graphics and am a bit lost...

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          You need to convert RGB values to grayscale values. The typically formula used is BYTE 8bitGrayscaleValue = (0.30 * RedByte) + (0.59 * GreenByte) + (0.11 * BlueByte) or the integer (no floating point) version: BYTE 8bitGrayscaleValue = (BYTE)((((int)RedByte * 30) + ((int)GreenByte * 59) + ((int)BlueByte * 11)) / 100); You could create a 24bpp DIB section the dimensions of the icon, select it into a memory DC, and draw the icon on the memory DC. Then using the pointer to the DIBSection's pixel bits, iterate through the RGB pixel values, converting each to grayscale. That's the easiest way I can think of to access the pixel data of an icon. Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          1 Reply Last reply
          0
          • _ __DanC__

            I am trying to create a grayscale version of an icon. I have extracted the icon and have an HICON but how would I create a grayscale version? I have been trying to figure it out and it seems I need to create an HDC and draw the icon into that but I am new to graphics and am a bit lost...

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            Also, this may help: CreateGrayscaleIcon[^] The use of GetPixel() and SetPixel() are way slower than accessing pixel data directly as I proposed in my previous post, if that's an issue. Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            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