[英]Save Bitmap image in a location in C#
I have this function to store the bmp image in a desired location as shown below My question is, how do I save the image in C:\\temp folder by default, instead of opening the filedialog box? 我具有将bmp图像存储在所需位置的功能,如下所示。我的问题是,如何默认将图像保存在C:\\ temp文件夹中,而不是打开文件对话框?
I want to specify sd.fileName=picname+".bmp" and store it in c:\\temp by default. 我想指定sd.fileName = picname +“。bmp”并将其默认存储在c:\\ temp中。
I tried to specify 我试图指定
Thanks for your help in advance. 感谢您的帮助。
I tried to 我试过了
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;
}
You need to set the InitialDirectory
of the SaveFileDialog
to "C:\\temp": 您需要将
SaveFileDialog
的InitialDirectory
设置为“ C:\\ temp”:
sd.FilterIndex = 1;
sd.InitialDirectory = @"C:\temp"; // <--- Add this line
if( sd.ShowDialog() != DialogResult.OK )
return false;
If I understand you correctly, you do not want to use a SaveFileDialog any at all. 如果我对您的理解正确,则根本不想使用SaveFileDialog。 Then I suggest you not to ;) .
那我建议你不要;)。 You are utilising SaveFileDialog to retrieve the path of the file which is SaveFileDialog.FileName in the line
您正在利用SaveFileDialog来检索该文件的路径,即该行中的SaveFileDialog.FileName
st = GdipSaveImageToFile( img, sd.FileName, ref clsid, IntPtr.Zero );
Instead of sd.FileName, put the value you want; 代替sd.FileName,放置所需的值; ie, @"c:\\temp\\" + picname + ".bmp"
即@“ c:\\ temp \\” +图片名称+“ .bmp”
Remove anything that is related to SaveFileDialog. 删除所有与SaveFileDialog相关的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.