Clas Member problem

This is a discussion on Clas Member problem within the Windows Programming forums, part of the Platform Specific Boards category; Hi, Im Using Visual C++ Windows Forms in Visual studio 2008 I am trying to use ToCOLORREF ( ToCOLORREF Method ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    28

    Exclamation Clas Member problem

    Hi,

    Im Using Visual C++ Windows Forms in Visual studio 2008

    I am trying to use ToCOLORREF (ToCOLORREF Method (ColorColor))

    However, I keep getting error...
    'ToCOLORREF' : is not a member of 'System:rawing::Color'

    Code:
    #include<gdiplus.h>
    #include<Gdipluscolor.h>
    #include<windows.h>
    Code:
    			 for(int i = 0; i < iImageW; i++)
    				 {
    					 for(int j = 0; j < iImageH; j++)
    					 {
    						 // Get the Pixel colour at i, j
    						 Color c1 = Bmp1->GetPixel(i, j);
    
    						 COLORREF crRGB = c1.ToCOLORREF();
    ...
    Anyone know why this won't work or can help me overcome this problem?


    thanks in adavnce

  2. #2
    Registered User
    Join Date
    May 2008
    Posts
    28
    Any Ideas?

    Is more info required of my problem?

  3. #3
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    It doesn't work because you're mixing functions from two different frameworks. ToCOLORREF is a GDI+ function, while this particular Color object is from .Net's System.Drawing. The two are roughly analogous, but nevertheless not interoperable. This is what you're working with so the ToArgb method would seem to be the equivalent.

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    224
    wrong way

  5. #5
    Registered User
    Join Date
    May 2008
    Posts
    28

    Question

    Quote Originally Posted by adeyblue View Post
    It doesn't work because you're mixing functions from two different frameworks. ToCOLORREF is a GDI+ function, while this particular Color object is from .Net's System.Drawing. The two are roughly analogous, but nevertheless not interoperable. This is what you're working with so the ToArgb method would seem to be the equivalent.
    Thanks for your reply!

    The reason I want to convert to COLORREF is to be able to convert from RGB to HLS using:
    ColorRGBToHLS() ColorRGBToHLS Function ()

    How else can I go about this?

    Thanks again

  6. #6
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    One possible solution...

    Code:
    #include<windows.h>
    #include<gdiplus.h>
    #include <Shlwapi.h>
    #include <stdio.h>
    
    #pragma comment (lib, "Gdiplus.lib")  
    #pragma comment (lib, "Shlwapi.lib")  
    
    using namespace Gdiplus;
    
    void Demo(void)
    {
        GdiplusStartupInput gdiplusStartupInput;
        ULONG_PTR gdiplusToken;
        Color c1;
        WORD Hue = 0;
        WORD Luminance = 0;
        WORD Saturation = 100;  
    
        GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
        Bitmap Bmp1(L"Test.bmp");
        int iImageW = Bmp1.GetWidth();
        int iImageH = Bmp1.GetHeight();
        printf("width %d height %d\n", iImageW, iImageW);
    
        for(int i = 0; i < iImageW; i++)
        {
            for(int j = 0; j < iImageH; j++)
            {
                Bmp1.GetPixel(i, j, &c1);
                COLORREF crRGB = c1.ToCOLORREF();
                ColorRGBToHLS(crRGB, &Hue, &Luminance, &Saturation);
            }
        }
    }
    
    int main(void)
    {
        Demo();
        return 0;
    }

  7. #7
    Registered User
    Join Date
    May 2008
    Posts
    28
    Hey, thanks for the suggestion!!!

    Is it necessary for me to go to this lengths just to convert the RGB to HLS?

    All I want to do is set the saturation to zero for a smooth gryscale gradient

  8. #8
    Registered User
    Join Date
    May 2008
    Posts
    28
    Any Ideas????

  9. #9
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Is it necessary for me to go to this lengths just to convert the RGB to HLS?
    All I want to do is set the saturation to zero for a smooth gryscale gradient
    Yep, this is necessary if you want to convert to HLS, change to grayscale and then possible convert back to RGB.

    The steps necessary to convert to grayscale are as follows:

    1. Get each pixel in the RGB image
    2. Convert RGB to HLS and get the saturation
    3. Set the saturation to 1 and convert back to RGB
    4. Set the new image pixel.

    The above entails adding four more statements to the demo code posted. IMHO, that isn't going to great lengths to accomplish your goal.

  10. #10
    Registered User
    Join Date
    May 2008
    Posts
    28
    Quote Originally Posted by BobS0327 View Post

    GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR gdiplusToken;





    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
    }[/CODE]
    What are these statements doing?

  11. #11
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Quote Originally Posted by paulogrady View Post
    What are these statements doing?
    The MSDN docs best describe what these statements are doing. Essentially, it initializes Microsoft Windows GDI+ and is required.

  12. #12
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    Quote Originally Posted by paulogrady View Post
    Is it necessary for me to go to this lengths
    It's necessary at some point because that's just how the API works, however you don't have to chuck your existing code and drop to native Gdi+. As the Argb value returned from ToArgb() is essentially just a backwards COLORREF, some bit twiddling is all that's required to be able to use the functions taking one.

    Code:
    // inside the for loops
    Color c1 = Bmp1->GetPixel(i, j);
    DWORD colorAsArgb = c1.ToArgb();
    // colorAsArgb stored as 0xAARRGGBB
    // instead of 0x00BBGGRR as a normal COLORREF
    // so we shift and mask the appropriate bits to convert
    COLORREF colorAsColorRef = RGB(LOBYTE(HIWORD(colorAsArgb)), HIBYTE(LOWORD(colorAsArgb)), LOBYTE(LOWORD(colorAsArgb)));
    WORD hue, luminence, saturation;
    ColorRGBToHLS(colorAsColorRef, &hue, &luminence, &saturation);
    // manipulate the hls values
    // however you want to
    colorAsColorRef = ColorHLSToRGB(hue, luminence, saturation);
    c1 = c1.FromArgb(GetRValue(colorAsColorRef), GetGValue(colorAsColorRef), GetBValue(colorAsColorRef));
    Bmp1->SetPixel(i, j, c1);

  13. #13
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Code:
    #using <mscorlib.dll>
    #using <System.dll>
    #using <System.Drawing.dll>
    
    using namespace System;
    
    int main(void)
    {
        System::Drawing::Bitmap Bmp("Test.bmp");
        for(int iIndexY = 0; iIndexY <Bmp.Height; iIndexY++)
        {
            for(int iIndexX = 0; iIndexX < Bmp.Width; iIndexX++)
            {
                System::Drawing::Color c = Bmp.GetPixel(iIndexX,iIndexY);
                int iGreyScale = (int)(c.R*0.3 + c.G*0.59+ c.B*0.11);
                Bmp.SetPixel(iIndexX,iIndexY,System::Drawing::Color::FromArgb(iGreyScale,iGreyScale,iGreyScale));
            }
        }
        Bmp.Save("NewTest.bmp");
    return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you check what is wrong with this code
    By Ron in forum C++ Programming
    Replies: 4
    Last Post: 08-01-2008, 10:59 PM
  2. "Account class" problem
    By freddyvorhees in forum C++ Programming
    Replies: 8
    Last Post: 07-27-2008, 08:31 AM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. problem accessing a struct member
    By ichijoji in forum C Programming
    Replies: 5
    Last Post: 03-09-2006, 09:59 PM
  5. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21