?
Solved

Load an image into a bitmap

Posted on 1998-06-08
8
Medium Priority
?
373 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 400 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

771 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