oops typo I missed out the hDC in SetPixel - - but the jist is there
Main Topics
Browse All Topicshi... I'm strugling to display a bitmap - I've read a lot of tutorials and books so don't send me to any... I would just like someone to write me a few lines of code for creating, and displaying a bitmap in windows (win98) using visualC++ (6.0) (no MFC - clean WinAPI please)
//I want to create an array:
//size is 64x64 and 3 colors (RGB)
unsigned char screen[64][64][3];
now I want to create a bitmap from this array and display it on the screen in a single window... how do I do that?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
to put the bitmap you have create onto a screen you will need a window to place it in and you wil need to know its HDC
then you can do - pobably in response to an WM_PAINT message
//to create a bitmap you will need a device context to draw it in
HDC hDC = ::CreateCompatibleDC(hWind
// then you need to select it into your DC
HBITMAP hOldBitmap = (HBITMAP)::SelectObject(hW
// display the bitmap
::BitBlt(hWindowDC,0,0,64,
// now we tidy up
// then you select in the old bitmap
::SelectBitmap(hDC,hOldBit
// delete old DC
::DeleteDC(hDC);
The one thing you must remember about windows and drawing is that you must tidy up - windows is very unforgiving and you will suffer resource leaks and lack of resources very quickly if you are not careful
const int width = 64;
const int height = 64;
const int stride = ( width * 3 + 3 ) / 4 * 4;
unsigned char screen[height][stride];
for (int y=0; y<height; y++)
for (int x=0; x<width; x++)
{
screen[y][x*3] = blue;
screen[y][x*3+1] = green;
screen[y][x*3+2] = red;
}
BITMAPINFO bmi = { { sizeof(BITMAPINFO), width, height,
1, 24 } };
StretchDIBits(hDC, x, y, width, height, ...);
www.fengyuan.com
I Could send you an Complet set of displaying and creating bitmaps in WinAPI Style...
I Use it for my Games...
You can read bitmaps from File and from Resource, and even create your own
Send me an email if you are interested: snewss@hotmail.com
you can give me the poits after you'vd gotten the file
It is wery easy to use...
Business Accounts
Answer for Membership
by: ShaunWildePosted on 2001-08-06 at 14:15:05ID: 6357262
//to create a bitmap you will need a device context to draw it in ; // create a DC that is compatible with the screen
DC,64,64);
C,hBitmap) ;
i][j][0],s creen[i][j ][1],scree n[i][j][2] ));
map);
HDC hDC = ::CreateCompatibleDC(NULL)
// then you need a DC to draw on
HBITMAP hBitmap = ::CreateCompatibleBitmap(h
// then you need to select it into your DC
HBITMAP hOldBitmap = (HBITMAP)::SelectObject(hD
// now you can draw on it
for (i=0;i<64;i++)
for (j=0;j<64;j++)
::SetPixel(i,j,RGB(screen[
// then you select in the old bitmap
::SelectBitmap(hDC,hOldBit
// delete old DC
::DeleteDC(hDC);
now hBitmap contains your image which you can do with what you will - the above will create a bitmap that has colours that match your screen - if you have limited colours you may have to play with palettes