Solved

bitmap bits of a memory DC

Posted on 2001-08-15
10
228 Views
Last Modified: 2013-12-03

Hi !

I've created a CDC, with the right height, width, palette (1 bit), etc. I draw some texts, bitmaps, etc.
I have to access the bits of the CDC, because I want to print it on a special printer that needs pixels as bits.

GetPixel works at all, but very slow. About 1.2 sec when I process the whole DC (pixel by pixel).
Are there any faster way to access the bits ?

I try to use the following:

CBitmap rbmp;
rbmp.CreateCompatibleBitmap(&dc,width,height);
unsigned char *bbmp=new unsigned char[width*height];
rbmp.GetBitmapBits(width*height,(void *)bbmp);

But all of the bits are 0.

What can I do ?

  Thx
0
Comment
Question by:stewe
  • 5
  • 4
10 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 6387711
I don't know these C++ classes (I'm a Delphi programmer), but using CreateCompatibleBitmap is probably the wrong choice. You should use CreateDIBitmap or CreateDIBSection. Furthermore you should use GetDIBits instead of GetBitmapBits.

Regards, Madshi.
0
 
LVL 1

Author Comment

by:stewe
ID: 6387723
I've examining these functions, but don't know how to do it.
Exmaple ?
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6387745
Can't give you a C(++) example. But it's not that difficult. Simply call CreateDIBSection. The parameter "ppvBits" will give you a fully functional pointer to the bits.

Regards, Madshi.
0
 
LVL 1

Author Comment

by:stewe
ID: 6387852

BITMAPINFO binfo;
binfo.bmiHeader.biSize=40;
binfo.bmiHeader.biWidth=width;
binfo.bmiHeader.biHeight=height;
binfo.bmiHeader.biPlanes=1;
binfo.bmiHeader.biBitCount=1;
binfo.bmiHeader.biCompression=BI_RGB;
binfo.bmiHeader.biSizeImage=width*height;
binfo.bmiHeader.biXPelsPerMeter=0;
binfo.bmiHeader.biYPelsPerMeter=0;
binfo.bmiHeader.biClrUsed=0;
binfo.bmiHeader.biClrImportant=0;
binfo.bmiColors[0].rgbRed=0;
binfo.bmiColors[0].rgbGreen=0;
binfo.bmiColors[0].rgbBlue=0;
binfo.bmiColors[1].rgbRed=255;
binfo.bmiColors[1].rgbGreen=255;
binfo.bmiColors[1].rgbBlue=255;

void **bits=NULL;
HBITMAP _hbmp=CreateDIBSection(dc.m_hDC,&binfo,DIB_RGB_COLORS,bits,NULL,0);

bits is NULL, _hbmp is invalid. So some of the parameters are wrong.

0
 
LVL 1

Author Comment

by:stewe
ID: 6387981

Ok. question deleted, I got the answer.
The solution:

At the beginning, I create an empty bitmap, and select into the memory DC. the select gives me back the original bitmap, that must be selected back after the drawing (of course).
So when selecting back, the select gives back my bitmap, BUT FILLED WITH ALL DRAWING INFO.
with CBitmap's GetBitmapBits function, I got the bits, and the time is 0 msec (of course GetTicketCnt() based on 10 msecs).

So. The question is deleted.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:stewe
ID: 6387982
I wrote it.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6387993
>> So. The question is deleted.

No problem.

Just for your interest:

LPVOID bits;
HBITMAP _hbmp=CreateDIBSection(dc.m_hDC,&binfo,DIB_RGB_COLORS,&bits,NULL,0);

Regards, Madshi.
0
 
LVL 1

Author Comment

by:stewe
ID: 6388095
You saw that I called at the same method. But some errors occured.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6388152
Yeah, but your "bits" parameter was wrong. In the two lines I've posted I've changed your code. Now it should work (I guess). But doesn't matter, if you found another solution, it's okay for me...
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8270989
Administrative action - PAQ'd and points NOT refunded.

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now