CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Picture image

  1. #1
    Join Date
    Feb 2009
    Posts
    56

    Picture image

    I'd like to display a color image in black and white only ? What should I adjust ?
    Thanks a lot
    -----

  2. #2
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    Re: Picture image

    Here is a link to convert a color bitmap into monochrome.
    http://support.microsoft.com/default.aspx/kb/77282
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  3. #3
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Picture image

    Quote Originally Posted by yuenqi View Post
    I'd like to display a color image in black and white only ? What should I adjust ?
    Thanks a lot
    When you say black and white, do you mean monochrome (literally only black pixel or white pixel) or do you mean greyscale (like a black and white photo)?

    If the former, see _Superman_'s link. If the latter, you'll have to go through each pixel and apply a formula to the red, green, and blue components, to convert to greyscale equivalent. The mathematical formula is:

    grey=0.2125*red+0.7154*green+0.0721*blue;

    To do this to an image, use something like this in a loop:

    Code:
      unsigned cr,rd,gn,bl,av;
    
      for(;;)  //do whatever to loop through your image here
      {
        cr=GetPixel(hdc,x,y);
        rd=GetRValue(cr);
        gn=GetGValue(cr);
        bl=GetBValue(cr);
        av=(rd*2125+gn*7154+bl*721)/10000;
        SetPixel(hdc,x,y,RGB(av,av,av));
      }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured