Solved

Load an image into a bitmap

Posted on 1998-06-08
8
371 Views
Last Modified: 2013-12-03
I have some raw 8-bit grayscale data that I want to load into a bitmap.  Can anyone give me directions on how to load this data and display it in a CFormView.  I'm using VC5.0 and MFC. Thanx

zeekial@yahoo.com
0
Comment
Question by:zeekial
[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
  • 3
  • 2
  • 2
  • +1
8 Comments
 

Author Comment

by:zeekial
ID: 1165382
Edited text of question
0
 
LVL 7

Expert Comment

by:galkin
ID: 1165383
Allocate memory by any function or C++ new operator. Read file into this buffer. Call CreateDIBitmap to create DIB. Then you can either use StretchDIBits, SetDIBitsToDevice to draw DIB or to convert it to DDB and then use BitBlt or StretchBlt
0
 

Author Comment

by:zeekial
ID: 1165384
Here's some code to show you where I stand:

int fh;
char buffer[60000];
unsigned int nbytes = 60000;

fh = open("imagefile",O_RDONLY)
read(fh, buffer, nbytes);

now all my data is in character buffer "buffer".  How do I put this data into a bitmap and BitBlt it?  
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:alamo
ID: 1165385
Is "imagefile" an actual image of a particular type, or is it simply a collection of bits?

How do you know the format (number of rows and columns) in imagefile?
0
 

Author Comment

by:zeekial
ID: 1165386
"imagefile" is raw data of a 300X200 grayscale image I saved from another program.
0
 
LVL 7

Expert Comment

by:galkin
ID: 1165387
IF THIS IS A GRAYSCALE IMAGE IT IS ASSUMED EACH BYTE in image data is between 0 and 255. So you can create grayscale palette and create DIB from you image data so that eacch byte would be corresponding index in the palette.
0
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
ID: 1165388
HDC DCHnd = CreateDC("DISPLAY",NULL,NULLNUL);
BITMAPINFORHEADER BMIH = {sizeof(BITMAPINFOHEADER),
300,
200,
1,
8,
BI_RGB,
0,
96,
96,
256,
256};

HBITMAP = CreateDIBitMap(DCHnd,&BMIH,CBM_INIT,Buffer,&BMI,DIB_RGB_COLORS);

This is approximately what you need. (I don't know all the details of what you have.)   If you have questions, ask.  Don't reject the answer without asking questions.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1165389
I haven't done this in so long I forgot something.  The BITMAPINFOHEADER  and BITMAPINFO and color table are ussually created as one structure.  Like
BITMAPINFO *BMIPtr = (BITMAPINFO *) new char[sizeof BITMAPINFOHEADER) + sizeof(RGBQUAD)*256];

Then you wild fill in the BITMAPINFOHEADER part as I showed above and fill in the color table appropriately (depending on your color format etc.)

We can discuss some of these things, but you might want to look into the docs on
BITMAPINFO BITMAPINFOHEADER and CreateDIBitMap() first.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

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