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?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mahesh1402IT ProfessionalCommented:
You are using VC++ or VC++.NET ?

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

Refer example code on this page :

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.

mahesh1402IT ProfessionalCommented:
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 :- <== REFER THIS

Refer example code on above link.

OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

mahesh1402IT ProfessionalCommented:
REFER This with Source Code :

Using the .NET Image Class <======

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?

mahesh1402IT ProfessionalCommented:
>> I want to create the image from scratch using the DrawLine, DrawString, FillRectangle, etc

look at Graphics::FromImage().

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



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual C++.NET

From novice to tech pro — start learning today.