Creating a jpeg or gif from a windows graphics form

My program uses input data to create a graph using the graphics class with a dialog box. I would like to be able to save the graph in a format that can be pasted into other applications such as Word. To do this, the graph would have to be converted into a standard format such as jpeg or gif. Sample coding of how to do this would be most appreciated. The graph is built using basic graphics methods such as"DrawLine", "DrawString", and "FillRectangle".

Most standard graphics applications such as powerpoint have file conversion options ("save as type:") as part of the "Save As" dialog. How would I access and use this feature?

restabroAsked:
Who is Participating?
 
mahesh1402Commented:
>> I want to create the image from scratch using the DrawLine, DrawString, FillRectangle, etc

look at Graphics::FromImage().

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/GDIPlus/GDIPlusreference/classes/imageclass/imagemethods/imagesavemethods/save_39filename_clsidencoder_encoderparams.asp

e.g u can do like :

Bitmap bm= new Bitmap(600,600);
Graphics g= Graphics::FromImage(bm);
g.DrawLine(myPen, 0, 0, 100, 100)

//Here also draw this line on screen with Graphics HDC

bm.Save(.....



MAHESH
0
 
mahesh1402Commented:
You are using VC++ or VC++.NET ?

Using GDI+ its easy task.. Refer Image::Save methods...

Refer example code on this page :

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/GDIPlus/GDIPlusreference/classes/graphicsclass/graphicsmethods/save.asp

MAHESH
0
 
restabroAuthor Commented:
I am using VC++.NET

I think the example your showed me is a way to save the graphic image on the stack so it can be recalled later for use in the same program. I didn't see anything in the exmaple that would save the graphic as a .jpg or a .gif file.

I am looking for something similar to the System::Drawing::Printing namespace, that provides properties and methods that bring up a standard Windows dialog box for saving a file, with an option to select the file format. Again, similar to the file "Save As" function you get with Powerpoint.

0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
mahesh1402Commented:
Oops sorry its my mistake I suggested you to Refer Image::Save method and I by mistake post you link for Graphics::Save method.....

Image::Save :-

http://msdn.microsoft.com/library/en-us/gdicpp/GDIPlus/GDIPlusreference/classes/imageclass/imagemethods/imagesavemethods.asp <== REFER THIS

Refer example code on above link.

MAHESH
0
 
mahesh1402Commented:
REFER This with Source Code :

Using the .NET Image Class
http://www.codeguru.com/columns/Kate/article.php/c4839/ <======



MAHESH
0
 
restabroAuthor Commented:
This is getting a lot closer to what I'm looking for. However, the examples both start with an image, modify it, then save the image as a jpeg, or another format. Will this same methodology work if there is no image to start with? In other words, I want to create the image from scratch using the DrawLine, DrawString, FillRectangle, etc., and then save the image I created from scratch to a jpeg.

Is there no way to access a standard Windows dialog box that contains the file browsing feature and File Type, again, like you find in Powerpoint? Is there anyway to use the System::Windows::Forms::SaveFileDialog class, or something similar to do this?

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.