|
-
April 9th, 2004, 05:15 PM
#1
How to get a pointer to starting bits of HBITMAP?
I have created a DC using CreateCompatibleDC and attached an HBITMAP created using CreateCompatibleBitmap(). Everything works fine with windows api's . I have tryed using GetObject(HBITMAP, ..., &BITMAP), The BITMAP.bmBits is alway's NULL .
Code:
temp = GetObject(hbit, 0, NULL);
bmp = (BITMAP *)malloc(temp);
GetObject(hbit, temp, bmp);
lptr = (long *)bmp->bmBits;
if(lptr == NULL){MessageBox(hwnd, "it is NULL", "nothing", 0);}
Anyone know how to get a pointer to the starting bits of a HBITMAP?
-
April 19th, 2004, 01:13 PM
#2
look this function GetBitmapBits. For Windows 2000 it works.
Good luck
-
April 20th, 2004, 07:39 AM
#3
I suggest:
hdc1 = CreateCompatibleDC(NULL);
hbmp1 = CreateBitmap(200,100,1,32,nil); //1 pixel = 32 bit, 200*100 pixel
SelectObject(hdc1,hbmp1);
hpen1 = CreatePen(PS_SOLID,1,255);
SelectObject(hdc1,hpen1);
MoveToEx(hdc1,0,0,NULL);
LineTo(hdc1,200,100);
//draw a red line
GetBitmapBits(hbmp1,200*100*4,lptr);
//or SetBitmapBits( ... )
The CreateCompatibleBitmap() does not work well on my computer (it created monochrome bitmap).
-
April 20th, 2004, 03:23 PM
#4
From MSDN library
GetBitmapBits
cbBuffer
Specifies the number of bytes to copy from the bitmap into the buffer.
I also thought that GetBitmapBits would work but then I was wondering why Can't I change color of pixels . It turns out that GetBitmapBits copies the bits lol. And I have to use SetBitmapBits to put the modifyed bits back.
The CreateCompatibleBitmap() does not work well on my computer (it created monochrome bitmap)
That also happened to me. What I did is create a window and did something similer:
Code:
HDC h;
HDC hnew;
HBITMAP hbmp;
h = GetDC(windowhwnd);
hnew = CreateCompatibleDC(h);
hbmp = CreateCompatibleBitmap(h, width, height)
SelectObject(hnew, hbmp);
Tada. Now we have a bitmap with default color bits .
CreateDibSection seems to be what I need . But there are some parameters that I don't understand ...
Last edited by answer; April 20th, 2004 at 03:29 PM.
-
April 21st, 2004, 02:27 PM
#5
Of course, it's correct. And here is the error:
HDC hDC = ::GetDC(hWnd);
HDC hMemDC = ::CreateCompatibleDC(hDC);
HBITMAP hBitmap = ::CreateCompatibleBitmap(hMemDC, 32, 32);
I cannot explain it. I think it's becase we deal with handles.
Good luck
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|