Click here to Skip to main content
15,125,104 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to save image and pdf formet in SaveFileDialog?
C#
public static bool SaveDIBAs( string picname, IntPtr bminfo, IntPtr pixdat )
		{
		SaveFileDialog sd = new SaveFileDialog();

		sd.FileName = picname;
		sd.Title = "Save bitmap as...";
		sd.Filter = "Bitmap file (*.bmp)|*.bmp|TIFF file (*.tif)|*.tif|JPEG file (*.jpg)|*.jpg|PNG file (*.png)|*.png|GIF file (*.gif)|*.gif|All files (*.*)|*.*";
		sd.FilterIndex = 1;
		if( sd.ShowDialog() != DialogResult.OK )
			return false;

		Guid clsid;
		if( ! GetCodecClsid( sd.FileName, out clsid ) )
			{
			MessageBox.Show( "Unknown picture format for extension " + Path.GetExtension( sd.FileName ),
							"Image Codec", MessageBoxButtons.OK, MessageBoxIcon.Information );
			return false;
			}
		
		IntPtr img = IntPtr.Zero;
		int st = GdipCreateBitmapFromGdiDib( bminfo, pixdat, ref img );
		if( (st != 0) || (img == IntPtr.Zero) )
			return false;

		st = GdipSaveImageToFile( img, sd.FileName, ref clsid, IntPtr.Zero );
		GdipDisposeImage( img );
		return st == 0;
		}
Posted
Updated 1-Apr-13 22:54pm
v2
Comments
   
What is "formet"?
File dialog boxes do not save anything, they are used to require a file name and obtain it from the user.
—SA
minu1989 2-Apr-13 2:26am
   
yes, i agree with you.I want to save file in different formet like pdf,doc,Image)bmp,tiff,jpg,png)etc in c# win-form.
   
OK, save it. What's the problem? Creation of the content is the problem, to be considered separately for each format, a bit too much for a single question...
—SA
[no name] 2-Apr-13 1:39am
   
Why don't you just add PDF to your filter?
minu1989 2-Apr-13 2:23am
   
A added pdf in filter. when i save file as image formet like bmp,TIFF,JPEG,PNG,GIF,gif save them, but in pdf formet it gives error.
   
Do we have to pull all the detail from you? What error..?
—SA

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900