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
Solved

How do I create a from an array?

Posted on 1997-10-22
2
629 Views
Last Modified: 2013-12-03
PIX_PTR is an array of colors(chars) which I should be able to display as a bitmap. The palette I will use is a 16 color palette of user defined colors. I am not going to deal with the palette issue here, but it is important to know that the only colors used are 0-15. I have used the following code to attempt to display the contents of PIX_PTR as a bitmap.

GetClientRect( hWnd, (LPRECT) &rect );
hbmp = CreateBitmap(320, 200, 1, 4, PIX_PTR);

hdc = GetDC(hWnd);
hdcMemory = CreateCompatibleDC(hdc);
hbmpOld = SelectObject(hdcMemory, hbmp);

BitBlt(hdc, 0, 0, 320, 200, hdcMemory, 0, 0, SRCCOPY);

SelectObject(hdcMemory, hbmpOld);
DeleteDC(hdcMemory);

ReleaseDC(hWnd, hdc);
DeleteObject(hbmp);

When the program is run, this code displays nothing. I can get it to display something by using a 1 in place of 4 in parameter 4 of CreateBitmap. Of course the display is monochrome and erroneous, but it does display something. I am not loading any palette information at this time, I plan to work on that after I get PIX_PTR to display something using any colors. I assume there is a predefined palette, default or otherwise.  I have also tried to use CreateBitmapIndirect with no success by using the following settings.

bm.bmType = 0;
bm.bmWidth = 320;
bm.bmHeight = 200;
bm.bmWidthBytes = 256;
bm.bmPlanes = 1;
bm.bmBitsPixel = 4;
bm.bmBits = PIX_PTR;
hbmp = CreateBitmapIndirect(&bm);

The information I can find on "bm"(BITMAP) is wrong or just not available. Do you know what values I should use for bmWidthBytes? What is bmWidthBytes? Since I am using only 16 colors shouldn't bmBits be set to 4?

I have spent a lot of time attempting to make this work, any suggestions you may have would be greatly appreciated.

--Wulf
0
Comment
Question by:wulf
2 Comments
 

Accepted Solution

by:
kw040597 earned 50 total points
ID: 1407785
The CreateBitmap() can be only used to create monochrome bitmap, use CreateDIBitmap() or CreateDIBSection() instead. The relevent structure is BITMAPINFOHEADER.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1407786
CreateBitmap() CAN be used to create color bitmaps.

bmWidthBytes should be 100;  I think that will fix things.  It should be the number of bytes across a single scan line of the bitmap rounded up to an even number.

since you have 200 pixels across and fit two pixels in a byte (4 bit color) you need 100 bytes across.  Since 100 is even, you don't need to round.
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 article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
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…
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…

829 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