Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading and Manipulating Bitmaps

Status
Not open for further replies.

msia81

Technical User
Oct 20, 2003
3
US
Hi,

Is there an easy way to load bitmaps from file and manipulate them using Visual C++? I've tried using LoadBitmap and LoadImage but am not having any luck. I'd like to be able to just read the bitmap from somewhere on my computer and then read its pixel information. Any suggestions?
 
I'm not at the 'puter with Visual Studio installed, so I can't check this... but try reading the whole file into an array of bytes, then cast that to a bitmap.
 
Yeah, that's what I ended up doing. Was a better option in the end than trying to find my way around the API. At least I had an idea what I was doing. Thanks for your reply!
 
I think this is what you may be looking for.
Code:
HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, "C:\mybitmap.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
if (hBitmap)
{
    CBitmap myBmp;
    myBmp.Attach(hBitmap);
    
    BITMAP bm;
    myBmp.GetBitmap(&bm);

    CDC dcImage;
    dcImage.CreateCompatibleDC (NULL);
    CBitmap* pOldBitmap = dcImage.SelectObject (&myBmp);
}
you now have access to the bitmap in 3 ways. Through CBitmap (myBmp) through the BITMAP structure (bm) and through a CDC ( dcImage).
O.B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top