[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

bitmap bits of a memory DC

Posted on 2001-08-15
10
Medium Priority
?
241 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

872 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