Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Load a 2D array of intensity into a CBitmap object

Posted on 1998-01-02
4
Medium Priority
?
304 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
[X]
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
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 100 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

688 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