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

Threaded View

  1. #1
    Join Date
    Oct 2001
    Location
    lake of fire and brimstone
    Posts
    1,628

    [RESOLVED] Read grayscale bitmap into array

    Hello,

    I need to read in an 8 bit grayscale bmp and I want the value of its pixels stored in an array (can do that myself). I can't seem to get the value between 0 and 255, I always get zero with the code below. What's wrong?

    Code:
     HANDLE hBitmap;  //Holds the Handle of the Bitmap once it is loaded.
     HDC hDC;  //Our temporary Device Context, which will be used to hold our Bitmap later on.
    
     hDC = CreateCompatibleDC(NULL);  //Create's a compatible Device Context(DC) and stores its value in 'hDC'.
    
     hBitmap = LoadImage(0,"E:\\Test.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE); //This loads our Image into memory and stores the handle in the variable "hBitmap". You may change the Directory from this API call to one containing your Image.
    
     //Get info about the bitmap
     
     BITMAP Bitmap;
     SIZE ImageSize;
    
     //Get info about the bitmap
     GetObject(hBitmap, sizeof(Bitmap), &Bitmap);
     ImageSize.cx=Bitmap.bmWidth;
     ImageSize.cy=Bitmap.bmHeight;
    
     SelectObject(hDC,hBitmap); //Puts our loaded Image into our temporary Device Context.
    
     for(int x=0;x<ImageSize.cx;++x)
     for(int y=0;y<ImageSize.cy;++y)
     {
      COLORREF color=GetPixel(hDC,x,y);
    
      // Problem here : color is always zero, I want the correct value and put it in an array
     }
    
     // Clean up
    
     DeleteDC(hDC);
    Last edited by Simon666; August 26th, 2010 at 07:16 AM. Reason: Managed to find something that works for me
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞
    ۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞۞

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