0
votes

This may sound very simple but I've lost a lot of time looking for answer

In my Windows phone 8 app I use the PhotoChooserTask to let the user choose the photo, and i get the path of the photo by using

string FileName = e.OriginalFileName;

where e is the PhotoResult argument of the Task. , let's say: FileName=

"C:\Data\SharedData\Comms\Unistore\data\18\k\2000000a00000018700b.dat" (selected from the cloud) or

"D:\Pictures\Camera Roll\WP_20140110_10_40_42_1_Smart.jpg" (from camera roll)

I want to save that string path and open it up and show the image again when the users reopen the app. But I cannot find a method to convert those string into Image data (BitmapImage or Stream)

Any idea?

2

2 Answers

0
votes
private void PhotoChooserTaskCompleted(object sender, PhotoResult e)
{
    if (e.TaskResult == TaskResult.OK)
    {                
        var image = new BitmapImage();
        image.SetSource(e.ChosenPhoto);
        SaveImageAsync(image);
    }
}

public async void SaveImageAsync(BitmapImage image)
{
    await Task.Run(SaveImage(image));
}


public async Task SaveImage(BitmapImage image)
{
    IStorageFolder folder = await ApplicationData.Current.LocalFolder
            .CreateFolderAsync("Images", CreationCollisionOption.OpenIfExists);

    IStorageFile file = await folder.CreateFileAsync(
            imageFileName, CreationCollisionOption.ReplaceExisting);

    using (Stream stream = await file.OpenStreamForWriteAsync())
    {                
        var wrBitmap = new WriteableBitmap(image);
        wrBitmap.SaveJpeg(stream, image.PixelWidth, image.PixelHeight, 100, 100);
    }
} 
0
votes

At Windows Phone 8.1 you can try "StorageFolder.GetFolderFromPathAsync" static method (if this API is available at your app flavor) and then get a stream for a necessary file from that folder.