Solved

Load a 2D array of intensity into a CBitmap object

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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