0
我的新發展WP7用一個簡單的例子例如試圖..無法使用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
有人可以說我在哪裏犯錯嗎?
@ Kylerr-謝謝你的回覆,是的,我只是在尋找那個,發現非常有用,它讓我整天瞭解更多abt隔離存儲。 – coder 2012-03-08 20:20:24