|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
GDI Question
I've been looking around on MSDN and the internet and can't find how to draw bitmaps with GDI(not plus). All I want to know is the syntax for drawing a bitmap(from a resource or external file) to a device context at a given coordinate. Thanks for any help.
|
|
#2
|
||||
|
||||
|
You're looking for the BitBlt() function.
http://msdn.microsoft.com/library/d...itmaps_0fzo.asp Hope this helps! ![]() |
|
#3
|
|||
|
|||
|
Yeah I found that much but how do I load and get a device context to a bitmap file or resource?
|
|
#4
|
||||
|
||||
|
You can load the image with LoadImage(), if loading from file, or LoadBitmap(), if loading from resource. Next, you need to get the device context for your current window, which you can obtain with GetDC(). After that, you have to create a compatible device context with GetCompatibleDC() and use BitBlt() to draw to it. The code would go something like this:
Code:
HDC hDC, hDCBmp; HBITMAP hBitmap; BITMAP bmp; hBitmap = LoadBitmap(...) or (HBITMAP)LoadImage(...); hDC = GetDC(hWnd); hDCBmp = CreateCompatibleDC(hDC); GetObject(hBitmap, sizeof(BITMAP), &bmp); SelectObject(hDCBmp, hBitmap); BitBlt(hDC,100,100, bmp.bmWidth,bmp.bmHeight, hDCBmp, 0,0, SRCCOPY); DeleteObject(hBitmap); DeleteDC(hDCBmp); ReleaseDC(hDC); Please note that this code is off the top of my head and I did not test it. However, it ought to be pretty close to what you need. Don't forget to check MSDN for more information on the functions. Hope this helps! ![]() |
|
#5
|
|||
|
|||
|
Thank you, i'll try it later.
|
|
#6
|
|||
|
|||
|
This code snippet is a memory leak. The hBitmap will never be released as it is still selected into the HDC.
You can not delete a GDI object while it is selected into a HDC. You must catch the returns of SelectObject() . Before the function exits you must restore the HDC to its original resources and delete the created ones. |
|
#7
|
|||
|
|||
|
yeah thanks I noticed that too. I had found the LoadBitmap function in MSDN before but it said that it was depricated and I was wondering what is supposed to replace it?
|
|
#8
|
|||
|
|||
|
LoadImage()
__________________
The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions. Frank Zappa |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > GDI Question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|