[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Load an image into a bitmap

Posted on 1998-06-08
8
Medium Priority
?
381 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

649 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