Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

Load a 2D array of intensity into a CBitmap object

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
cw43
Asked:
cw43
1 Solution
 
jhanceCommented:
Use the CBitmap::SetBitmapBits() member function.
0
 
cw43Author Commented:
I have tried SetBitmapBits() after my CBitmap::CreateBitmap() function.  It does not work, nothing shown on the screen.  However, LoadBitmap() simply works.
0
 
chensuCommented:
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
 
galkinCommented:
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now