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. How to like XP shutdown to transfer color to gray

How to like XP shutdown to transfer color to gray

Scheduled Pinned Locked Moved C / C++ / MFC
9 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.
  • I Offline
    I Offline
    inforix
    wrote on last edited by
    #1

    Anyone how to transfer color to gray like XP shutdown interface. However, only the window is color, others is gray. What I needed maybe you have, so let's help each other.

    C 1 Reply Last reply
    0
    • I inforix

      Anyone how to transfer color to gray like XP shutdown interface. However, only the window is color, others is gray. What I needed maybe you have, so let's help each other.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      No need to barter :) To make colour into gray scale, you need to take the red, green abd blue values ( actually windows uses BGR ) and then use the formula x = .299 * red + .587 * green + .114 * blue to get the value to pass back in to all three values ( gray pixels having equal values in all three channels ). You can take an average of the three, but that doesn't take in to account the way the human eye percieves colour. Now, to change the whole screen to gray ( I assume that's what XP does, hey, maybe you DO have something I want....), you need to grab the screen ( which is easy - CWindowDC dc(NULL); gives you a DC to the screen, you can Blt off it ). Then you need to create a DIBSection the same size ( because you can get direct access to the bits ), copy the CWindowDC onto it ( it needs to be selected in to a DC, obviously ) and traverse the bits using this formula. Then copy the DIBSection back over the WindowDC. If you're doing it IN XP, or don't mind depending on the GDI+ dll, then you'll find the job easier because you can use a GDI+ bitmap to traverse the bits. I'll be writing a tutorial on how to do this shortly ( i.e. when I find time ). Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

      I 1 Reply Last reply
      0
      • C Christian Graus

        No need to barter :) To make colour into gray scale, you need to take the red, green abd blue values ( actually windows uses BGR ) and then use the formula x = .299 * red + .587 * green + .114 * blue to get the value to pass back in to all three values ( gray pixels having equal values in all three channels ). You can take an average of the three, but that doesn't take in to account the way the human eye percieves colour. Now, to change the whole screen to gray ( I assume that's what XP does, hey, maybe you DO have something I want....), you need to grab the screen ( which is easy - CWindowDC dc(NULL); gives you a DC to the screen, you can Blt off it ). Then you need to create a DIBSection the same size ( because you can get direct access to the bits ), copy the CWindowDC onto it ( it needs to be selected in to a DC, obviously ) and traverse the bits using this formula. Then copy the DIBSection back over the WindowDC. If you're doing it IN XP, or don't mind depending on the GDI+ dll, then you'll find the job easier because you can use a GDI+ bitmap to traverse the bits. I'll be writing a tutorial on how to do this shortly ( i.e. when I find time ). Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

        I Offline
        I Offline
        inforix
        wrote on last edited by
        #3

        Is there any sample? What I needed maybe you have, so let's help each other.

        C 1 Reply Last reply
        0
        • I inforix

          Is there any sample? What I needed maybe you have, so let's help each other.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          I have a sample around here somewhere that shows how to use a DIBSection to get access to the bits of a bitmap, but it's going to appear in next months Windows Developers Journal, so I'm not sure if I'm allowed to post it. What part of the explanation I gave do you need help with ? To get access to the screen bitmap, you'd do something like: CWindowDC window(NULL); CDC dc(NULL); // Does two different things, NULL in the first case creates a DC of the screen, the second creates one *compatible* with the screen. dc.SelectObject(dib); // Assumes it's already created to the screen size dc.BitBlt(0,0, width, height, &window, 0, 0); // viola. You might actually find if you download Paintlib (ww.paintlib.de ) it has stacks of examples of direct pixel access, and a nice wrapper for DIBsection. Also, if you want it, I've written a Targa saver, and filters including a 3x3 spatial with smooth, sharpen, emboss, etc., and gamma, colour, and I'm sure others, but I can't recall. Nothing too cool, no hot wax or swirl ( yet... ) LMK if you need more help, but that should get you started. Just post some code to show me where you get stuck. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

          I 1 Reply Last reply
          0
          • C Christian Graus

            I have a sample around here somewhere that shows how to use a DIBSection to get access to the bits of a bitmap, but it's going to appear in next months Windows Developers Journal, so I'm not sure if I'm allowed to post it. What part of the explanation I gave do you need help with ? To get access to the screen bitmap, you'd do something like: CWindowDC window(NULL); CDC dc(NULL); // Does two different things, NULL in the first case creates a DC of the screen, the second creates one *compatible* with the screen. dc.SelectObject(dib); // Assumes it's already created to the screen size dc.BitBlt(0,0, width, height, &window, 0, 0); // viola. You might actually find if you download Paintlib (ww.paintlib.de ) it has stacks of examples of direct pixel access, and a nice wrapper for DIBsection. Also, if you want it, I've written a Targa saver, and filters including a 3x3 spatial with smooth, sharpen, emboss, etc., and gamma, colour, and I'm sure others, but I can't recall. Nothing too cool, no hot wax or swirl ( yet... ) LMK if you need more help, but that should get you started. Just post some code to show me where you get stuck. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

            I Offline
            I Offline
            inforix
            wrote on last edited by
            #5

            I wrote the following code, but it give me a red screen, everything become red-like, not gray. CWindowDC dc(NULL); for ( int i=0; i<1024; i++) for ( int j=0; j<768; j++) { COLORREF clr = dc.GetPixel(i, j); int R = GetRValue(clr); int G = GetGValue(clr); int B = GetBValue(clr); clr = (54 * R + 183 * G + 19 * B)/256; //clr = 0.299 * B + 0.587 * G + 0.114 * R; //.299 * red + .587 * green + .114 * blue dc.SetPixel(i, j, clr); } What I needed maybe you have, so let's help each other.

            L C 2 Replies Last reply
            0
            • I inforix

              I wrote the following code, but it give me a red screen, everything become red-like, not gray. CWindowDC dc(NULL); for ( int i=0; i<1024; i++) for ( int j=0; j<768; j++) { COLORREF clr = dc.GetPixel(i, j); int R = GetRValue(clr); int G = GetGValue(clr); int B = GetBValue(clr); clr = (54 * R + 183 * G + 19 * B)/256; //clr = 0.299 * B + 0.587 * G + 0.114 * R; //.299 * red + .587 * green + .114 * blue dc.SetPixel(i, j, clr); } What I needed maybe you have, so let's help each other.

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

              You need to write something like this: int newclr = (54 * R + 183 * G + 19 * B)/256; clr = RGB(newclr, newclr, newclr) to put data in all three channels.

              I 1 Reply Last reply
              0
              • L Lost User

                You need to write something like this: int newclr = (54 * R + 183 * G + 19 * B)/256; clr = RGB(newclr, newclr, newclr) to put data in all three channels.

                I Offline
                I Offline
                inforix
                wrote on last edited by
                #7

                Thanks, I have correctted it. But there still has a problem: some area also is colourful, not gray, such as title bar, part of task bar. :laugh: What I needed maybe you have, so let's help each other.

                C 1 Reply Last reply
                0
                • I inforix

                  Thanks, I have correctted it. But there still has a problem: some area also is colourful, not gray, such as title bar, part of task bar. :laugh: What I needed maybe you have, so let's help each other.

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  Please stop saying What I needed maybe you have, so let's help each other it sounds so mercenary. I help people to help them, I'm sure others here do the same and it is a given that you will probably help me if you can later on. Anyhow, these areas are drawn by windows, you won't be able to draw on them using this method. The mouse pointer is the same. What is happen is that GDI allows you to draw out of bounds without a crash it just ignores the call. BTW you should add code to check the screen size to your loop - use GetSystemMetrics to do that. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

                  1 Reply Last reply
                  0
                  • I inforix

                    I wrote the following code, but it give me a red screen, everything become red-like, not gray. CWindowDC dc(NULL); for ( int i=0; i<1024; i++) for ( int j=0; j<768; j++) { COLORREF clr = dc.GetPixel(i, j); int R = GetRValue(clr); int G = GetGValue(clr); int B = GetBValue(clr); clr = (54 * R + 183 * G + 19 * B)/256; //clr = 0.299 * B + 0.587 * G + 0.114 * R; //.299 * red + .587 * green + .114 * blue dc.SetPixel(i, j, clr); } What I needed maybe you have, so let's help each other.

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #9

                    I should also mention that the reason I suggested copying to a DIBSection is that GetPixel is painfully slow compared to iterating through the bits using the pointer a DIBSection's constructor gives you. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

                    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