简体   繁体   中英

Save edited image to Camera Roll

I am new to C# and learning to develop for Windows Phone 8. I am making an image editing app. Is there a way to save edited image in camera roll instead of saved pictures.

using PhotoChooserTask returns a PhotoResult.

    private WriteableBitmap _imageBitmap = null;

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        PhotoChooserTask chooser = new PhotoChooserTask();
        chooser.Completed += choosenImage;
        chooser.Show();
    }

    private void choosenImage(object sender, PhotoResult e)
    {
        if (e.TaskResult != TaskResult.OK ) { return; }
        _imageBitmap.SetSource(e.ChosenPhoto);
        dummyImage.Source = _thumbImageBitmap;

        //MediaLibrary library = new MediaLibrary();
        //library.SavePictureToCameraRoll(String, Stream);
    }

I want to save this PhotoResult(image) in the Camera Roll. I did a little bit of research and found

MediaLibrary.SavePictureToCameraRoll Method

This method helps to

MediaLibrary.SavePictureToCameraRoll (String, Stream)
Save the specified image Stream as a Picture in the Windows Phone camera roll.

OR

MediaLibrary.SavePictureToCameraRoll (String, Byte[])
Save the specified byte array as a Picture in the Windows Phone camera roll.

How do I implement this method in my code?

e.ChosenPhoto is already a stream, so you can just set it like so:

EDIT: This should fix the issue with using the stream twice. You may be able to simply seek to the start of the stream and reuse e.ChosenPhoto , but I can't test that until I get home.

private void choosenImage(object sender, PhotoResult e)
{
    if (e.TaskResult != TaskResult.OK ) 
    { 
        return;
    }
    Stream theCopy = new Stream();
    e.ChosenPhoto.CopyTo(theCopy);
    e.ChosenPhoto.Seek( 0, SeekOrigin.Begin );

    _imageBitmap.SetSource(e.ChosenPhoto);
    dummyImage.Source = _thumbImageBitmap;

    MediaLibrary library = new MediaLibrary();
    library.SavePictureToCameraRoll(String, theCopy);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM