Solved

How to create a bitmap for pictureBox

Posted on 2004-04-26
10
948 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
[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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Compile GLUT with Visual Studio 2015 1 206
Header of docx file 17 131
C++ :Change value from  DisableCMD registry 4 69
Why isn't object file created? 6 91
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 how to clear a vector as well as how to detect empty vectors in C++.

749 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