Search code examples
bitmapmfcpixelcoordinate

Get pixel value from BITMAP file


I use VS2010 MFC.

I want to do following steps.

  1. Load Bitmap file(640x480, 8bit).
  2. Set coordinate. (x,y)
  3. Get pixel value from coordinate (0~255).

But I don't know steps...

Please advise me :)


Solution

  • This should works:

    #include "atlimage.h" // This is neccesary to use CImage objects from GDI+
    
    void dummy ()
    {
        std::string bitmapFile = "file.bmp"; // Full path of your bitmap file
        int x = 0; // Your x coordinate
        int y = 0; // Your y coordinate
    
        CImage image;
        if ( SUCCEEDED ( image.Load ( bitmapFile.c_str() ) ) )
        {
            COLORREF color = image.GetPixel ( x, y );
        }
    }