Solved

How to create a bitmap for pictureBox

Posted on 2004-04-26
10
945 Views
Last Modified: 2013-12-03
Hi all, I have a raw file in ppm standard (uncompressed, have RGB and header information of the width and height of the file).
I want to display it in my windows form but it seems that pictureBox does not accept PPM file.
Is there a way I can say if the file selected is a ppm file, i will create a bitmap object and put it into the pictureBox?

I checked around and believe that HBITMAP is gonna be the class object i will be creating the bitmap at.. but i am not sure how to set the R, G, B in the bitmap, (I assume its a 24bits/pixel)

What i will do is i will just read in the file stream, and set the R, G, B to the HBITMAP (or any other better choice??) object, then I will set it to the pictureBox(again, is there a way to directly set the item in pictureBox to a HBITMAP (or better choice?) object?

Thanks for any input..
0
Comment
Question by:lordiano
  • 5
  • 5
10 Comments
 

Author Comment

by:lordiano
ID: 10925630
Actually, I will do the checking for if the input file is a ppm file or a bmp..

I just need help on making a Bitmap object and help on setting the picturebox to display the bitmap object.
0
 
LVL 3

Expert Comment

by:CoolBreeze
ID: 10925652
on 'making' the Bitmap object, you might like to check this out:
http://support.microsoft.com/default.aspx?scid=kb;en-us;158898

regarding picturebox control, are you using .NET?
0
 

Author Comment

by:lordiano
ID: 10925679
Yes, I am running the application form in managed VC++
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 3

Expert Comment

by:CoolBreeze
ID: 10925729
if using .NET, and PictureBox1 is your picturebox control,
i think you can do this:

Image* imageFile = Image.FromFile("SampImag.jpg");
PictureBox1.set_Image(imageFile);
0
 

Author Comment

by:lordiano
ID: 10925994
Is there already a .DLL written to convert ppm file to HBITMAP?
cuz it seems that NVIEWLIB.DLL does the trick for jpeg and bmp files but i am just wondering if anyone knows any DLL that already does the trick for ppm to HBITMAP..
0
 
LVL 3

Expert Comment

by:CoolBreeze
ID: 10926041
you might be interested in this, FreeImage:
http://www.codeproject.com/bitmap/graphicsuite.asp
0
 

Author Comment

by:lordiano
ID: 10927670
Hi CoolBreeze, thanks for the link but unfortunately its not really what I wanted though, RIght now what i do was I created a Bitmap * mybmp
And i set the size of it according to the header information in the ppm file..
THen i use setpixel function to set each pixel in mybmp according the the ppm file.
Right now i am stuck on how to display this Bitmap * in my form.. or maybe my pictureBox , whichever is easier :)
Any idea?
0
 
LVL 3

Expert Comment

by:CoolBreeze
ID: 10927814
try something like:

Bitmap* MyImage = Image.FromHBitmap(hbitmap);
PictureBox1->Image = dynamic_cast<Image*>(MyImage);

?
0
 
LVL 3

Accepted Solution

by:
CoolBreeze earned 500 total points
ID: 10927837
oops. since you already have the Bitmap, you can just go straight to the second line.
PictureBox1->Image = dynamic_cast<Image*>(MyImage);
0
 

Author Comment

by:lordiano
ID: 10928366
thanks CoolBreeze
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

Suggested Solutions

Title # Comments Views Activity
PDF library for Delphi 2 128
Source of man or women figure in Text Box 7 110
Problem with SqlConnection 4 178
How do i run a c++ file? 15 46
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 …
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

839 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