保存位图图像而无需打开savefiledialog [英] Save bitmap image without open savefiledialog

查看:160
本文介绍了保存位图图像而无需打开savefiledialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有将图像保存为位图但使用savefiledialog的代码.
如果我不想使用savefiledialog,而只是想将映像保存到应用程序路径中的特定文件夹中,我该如何在vb net中执行此操作?

好吧,让我解释一下.我有一个已渲染的条形码图像,我需要将其另存为位图,而无需打开savefiledialog.
这样,用户可以将条形码扫描到datagridviewer中,然后将图像命名为与条形码相同,并保存到应用程序路径中的Barcodes文件夹中.

希望这更有意义.:confused:

解决方案

那真的很简单.

Path.GetDirectoryName(Assembly.GetCallingAssembly.Location)为您提供启动程序的文件夹.

然后,只需添加要放入的文件夹和文件名即可.

让我向您展示我在程序中使用的一些代码的摘录.

 ' 获取应用程序路径
 Dim 调用Dir  as   String  = Path.GetDirectoryName (Assembly.GetCallingAssembly.Location)

' 查看SpellCheck目录是否存在.如果没有,请创建它.
如果 不是目录.存在(callingDir& "  \ SpellCheck")" )
   Dim  newDirInfo  as   New  DirectoryInfo(callingDir& ; " )
  newDirInfo.Attributes = FileAttributes.Hidden
结束 如果

' 查看AddedWords文件是否存在.如果是这样,请将单词添加到字典中.
如果 File.Exists(callingDir& "  然后
  ' 对文件进行处理
结束 如果 


看看位图.保存 [ Application.ExecutablePath [ ^ ],然后调用 Bitmap.Save(string) [ ^ ].


I have code that saves an image as a bitmap but uses the savefiledialog.
If I didn''t want to use savefiledialog but just wanted to save the image to a specific folder in the application path how would I do that in vb net?

Well, let me explain it a bit more. I have a barcode image that is rendered and I need to save that as a bitmap without opening the savefiledialog.
This way the user can just scan the barcodes into the datagridviewer and then the image would be named the same as the barcode and saved to Barcodes folder in the applications path.

Hope this makes more sense.:confused:

解决方案

That''s really quite a simple thing to do.

Path.GetDirectoryName(Assembly.GetCallingAssembly.Location) gives you the folder that the program was started in.

Then, it''s just a matter of adding the folder you want it put in and the file name you want it to be.

Let me show you an excerpt of some code I use in a program.

'Get the application path
Dim callingDir as String = Path.GetDirectoryName(Assembly.GetCallingAssembly.Location)

'See if the SpellCheck directory exists.  If not, create it.
If Not Directory.Exists(callingDir & "\SpellCheck") Then
  Directory.CreateDirectory(callingDir & "\SpellCheck")
  Dim newDirInfo as New DirectoryInfo(callingDir & "\SpellCheck")
  newDirInfo.Attributes = FileAttributes.Hidden
End If

'See if the AddedWords file exists.  If so, add the words to the dictionary.
If File.Exists(callingDir & "\SpellCheck\AddedWords.dat" Then
  'Do something with the file
End If


Have a look at the Bitmap.Save[^] method.


You can obtain the application''s executable path with Application.ExecutablePath[^] and then call Bitmap.Save(string)[^].


这篇关于保存位图图像而无需打开savefiledialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆