Solved

bitmap bits of a memory DC

Posted on 2001-08-15
10
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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
 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

732 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