Solved

Load a 2D array of intensity into a CBitmap object

Posted on 1998-01-02
4
282 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

705 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

17 Experts available now in Live!

Get 1:1 Help Now