0

私は簡単な例を試してwp7開発を始めたばかりです..

私は画像コントロールと2つのボタンを持っています。1つは画像を読み込んで画像コントロールに表示するためのもので、もう1つはその画像を作成する必要がある新しいフォルダーに保存するためのものです。

以下のコードがあり、エラーは発生していませんが、ディレクトリを作成して既存の画像をそのフォルダーに保存できないという問題があります。

保存した後、ディレクトリとイメージを表示できません。

エミュレーターでフォルダーを確認できますか (または) 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

私がどこで間違いを犯しているのか、誰か教えてもらえますか?

4

1 に答える 1

1

コードは完璧です。問題は、Silverlight がファイルの保存に「分離ストレージ」を使用していることです。これは、名前が示すように、完全に分離されたストレージです。アプリケーションによって作成されたファイルまたはディレクトリは、アプリケーションからのみアクセスできます。

エミュレーターは、再起動後にそれらを保持する必要がないため、分離されたストレージファイルをメモリにのみ保存していると思います。アプリケーションの分離ストレージ内を簡単に確認したい場合は、Wp7 Explorer のようなツールを使用できます: http://wp7explorer.codeplex.com/

于 2012-03-08T20:01:12.597 に答える