Solved

Load a 2D array of intensity into a CBitmap object

Posted on 1998-01-02
4
285 Views
Last Modified: 2013-12-03
Say I have a 100x100 unsigned char array with intensities from 0~255, and I would like to display it via a CBitmap object on a CView class.  How do I pass this array into a CBitmap object to be able to display it?  
0
Comment
Question by:cw43
4 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 1409807
Use the CBitmap::SetBitmapBits() member function.
0
 

Author Comment

by:cw43
ID: 1409808
I have tried SetBitmapBits() after my CBitmap::CreateBitmap() function.  It does not work, nothing shown on the screen.  However, LoadBitmap() simply works.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1409809
CBitmap is a device dependent bitmap, which means its bits information depends on the display card and the display driver. You can set the bitmap bits correctly if it is monochrome (0 & 1). Otherwise you need to use a DIB.
0
 
LVL 7

Accepted Solution

by:
galkin earned 50 total points
ID: 1409810
Construct DIB. Create BITMAPINFO, fill BITMAPINFOHEADER structure. Allocate array 100x100 bytes using GlobalAllock and lock it using GlobalLock. Handle to this global memory is your DIB. Then create monochrome 256 entry palette using CreatePalette from array of LOGPALETTE structures. In Set bits according to the intencity by simply specifying correct ofset to allocated block of memory and compying corresponding number. Then you can use StrecthDIBits function to send DIB to target DC. Specify DIB_PAL_COLORS in iUsage in StrecthDIBits function but prior to calling it select and realize the palette you constructed. Unfortunaly there is no MFC DIB wrapper class so you must use API.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

948 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now