我是 wp7 开发的新手,尝试使用一个简单的示例,即..
我有一个图像控件和 2 个按钮,一个用于加载图像并将其显示在图像控件中,另一个用于将该图像保存到我需要创建的新文件夹中。
我有以下代码,我没有收到任何错误,但问题是我无法创建目录并将现有图像保存到该文件夹。
保存后我无法看到目录和图像。
我们能不能在模拟器中看到文件夹(或者)只能在windows phone上看到创建的目录?
Imports System.IO
Imports Microsoft.Phone.Tasks
Imports System.IO.IsolatedStorage
Imports System.Windows.Media.Imaging
Partial Public Class Page1
Inherits PhoneApplicationPage
Public Sub New()
InitializeComponent()
photoChooserTask = New PhotoChooserTask()
AddHandler photoChooserTask.Completed, AddressOf photoChooserTask_Completed
End Sub
Dim photoChooserTask As PhotoChooserTask
Private Sub photoChooserTask_Completed(sender As Object, e As PhotoResult)
Dim bmp As System.Windows.Media.Imaging.BitmapImage = New System.Windows.Media.Imaging.BitmapImage()
bmp.SetSource(e.ChosenPhoto)
Image1.Source = bmp
Dim originalFilename = Path.GetFileName(e.OriginalFileName)
SaveImage(e.ChosenPhoto, originalFilename, 0, 100)
End Sub
Public Shared Sub SaveImage(ByVal imageStream As Stream, ByVal fileName As String, ByVal orientation As Integer, ByVal quality As Integer)
Using isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()
If isolatedStorage.FileExists("NewPics\fileName") Then
isolatedStorage.DeleteFile("NewPics\fileName")
End If
If Not isolatedStorage.DirectoryExists("NewPics") Then
isolatedStorage.CreateDirectory("NewPics")
End If
'isolatedStorage.CreateDirectory("NewPics")
'Dim fileStream As New IsolatedStorageFileStream("fileName", FileMode.Create, isolatedStorage)
Dim fileStream = isolatedStorage.CreateFile("NewPics\" + fileName)
Dim bitmap = New BitmapImage()
bitmap.SetSource(imageStream)
Dim wb = New WriteableBitmap(bitmap)
wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, orientation, quality)
fileStream.Close()
End Using
End Sub
Private Sub Button1_Click(sender As Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
Try
photoChooserTask.Show()
Catch ex As System.InvalidOperationException
MessageBox.Show("An error occurred.")
End Try
End Sub
End Class
谁能告诉我我在哪里犯错?