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 

有人可以說我在哪裏犯錯嗎?

回答

1

的代碼是完美的,問題是,Silverlight使用「分離的存儲」用於存儲文件,這是,顧名思義,一個完全獨立存儲。由您的應用程序創建的文件或目錄只能從您的應用程序訪問。

我認爲模擬器只是在內存中存儲隔離的存儲文件,因爲它不必在重新啓動後保留它們。如果你想在你的應用程序的隔離存儲器裏面輕鬆看到,你可以使用像Wp7 Explorer這樣的工具:http://wp7explorer.codeplex.com/

+0

@ Kylerr-謝謝你的回覆,是的,我只是在尋找那個,發現非常有用,它讓我整天瞭解更多abt隔離存儲。 – coder 2012-03-08 20:20:24

相關問題