0

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 Answers1

0

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
Clemens
  • 123,504
  • 12
  • 155
  • 268