Solved

bitmap bits of a memory DC

Posted on 2001-08-15
10
234 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

830 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