如何使用OpenFileDialog浏览图像并将其保存在图像文件夹中 - Silverlight OOB - VB [英] How to browse an image using OpenFileDialog and save it in images folder - Silverlight OOB - VB

查看:180
本文介绍了如何使用OpenFileDialog浏览图像并将其保存在图像文件夹中 - Silverlight OOB - VB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VB开发一个Silverlight OOB应用程序,我需要实现一个方法,用户通过OpenFileDialog文件选择一个图像(.png)并将该图像保存在项目的Images文件夹中,因为它不是可以将Source设置为一个不在项目中的Image,然后我需要将它保存在Images文件夹中,但我不知道怎么做,有人帮我请!!!以下是我现在所做的事情:

I'm developing an Silverlight OOB application using VB, and I need to implement a method where the user select an image (.png) by an OpenFileDialog file and it saves this image in Images folder in the project, because it's not possible to set a Source to an Image that it's out of project, then I need to save it in Images folder, but I have no idea how to do this, someone helps me please!!! Here's what I did up to now:

Dim ofd As OpenFileDialog = New OpenFileDialog
ofd.Filter = "Image Files (*.png)|*.png"
ofd.FilterIndex = 1

If ofd.ShowDialog() Then
    Dim imgd As String = ofd.File.DirectoryName & "\" & ofd.File.Name
    Dim img As BitmapImage = New BitmapImage(New Uri(imgd))
End If


推荐答案

您无需复制文件。

只需检查在项目的浏览器外设置中在浏览器外部运行时需要提升信任,并通过 FileStream 加载图像文件而不是一个 Uri

Just check Require elevated trust when running outside the browser in the Out-of-Browser Settings of your project, and load the image files via a FileStream instead of an Uri.

Dim path As String = "C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg"
Dim bitmap As BitmapImage = New BitmapImage

Using stream As FileStream = New FileStream(path, FileMode.Open, FileAccess.Read)
    bitmap.SetSource(stream)
End Using

这篇关于如何使用OpenFileDialog浏览图像并将其保存在图像文件夹中 - Silverlight OOB - VB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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