• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

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?

0
restabro
Asked:
restabro
  • 6
  • 2
1 Solution
 
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
 
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now