Solved

How to create a bitmap for pictureBox

Posted on 2004-04-26
10
940 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

759 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

25 Experts available now in Live!

Get 1:1 Help Now