Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

bitmap bits of a memory DC

Posted on 2001-08-15
10
Medium Priority
?
239 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

618 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