Solved

How to create a bitmap for pictureBox

Posted on 2004-04-26
10
941 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 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.
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now