How to browse an image using OpenFileDialog and save it in images folder - Silverlight OOB - VB

余生颓废 提交于 2019-12-13 03:02:40

问题


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

回答1:


You don't need to copy files.

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


来源:https://stackoverflow.com/questions/24946504/how-to-browse-an-image-using-openfiledialog-and-save-it-in-images-folder-silve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!