Solved

Load an image into a bitmap

Posted on 1998-06-08
8
358 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 learn how to clear a vector as well as how to detect empty vectors in C++.

860 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