Save a photo to Windows Phone Gallery?

Asked

Viewed 164 times

1

I am using the following code to save the image in Isolatestorage:

String tempJPEG = "/Shared/Media/card.jpg";
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
    if (myIsolatedStorage.FileExists(tempJPEG))
    {
        myIsolatedStorage.DeleteFile(tempJPEG);
    }
    IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG);
    Extensions.SaveJpeg(bmp, fileStream, bmp.PixelWidth, bmp.PixelHeight, 0, 85);
    fileStream.Close();
}

And this code to try to save the image in the gallery:

using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
    using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("/Shared/Media/card.jpg", FileMode.Open, FileAccess.ReadWrite))
    {

        MediaLibrary mediaLibrary = new MediaLibrary();
        mediaLibrary.SavePicture("SavedCard.jpg", fileStream);
        fileStream.Close();
    }
}

But when I try to run the app, it closes and in Visual gives this error: erro

I’ve been trying to solve this problem for days. I found an example, but it uses image of the project itself, so it is easy, in my case the image is of the project, but it is edited by the user and saved in Isolatestorage..

  • I don’t know this but the error indicates that the user does not have access to the location. It doesn’t seem to be a problem in the code other than the fact that it doesn’t handle the exception.

  • I do not know exactly why the error, in the code that I saw the image was original app, and there is a folder of SD Card or Phone where the app is stored, and even saving this image there gives the same error, so I do not believe it is the permission problem.. Very strange this rs

1 answer

1


This error happens when you do not give the permission of the application to access the image gallery.

First, go on Propities > Wmappmanifest.xml

WMAppManifest.xml

If it is 8.1, you also have to enable in Package.appxmanifest

Package.appxmanifest

  • It was worth a lot bro, I did a test here in a new app and it worked, I hope when you deploy in the app I wanted to deploy work! I had already given up, had taken the feature of the app and published it in the store, but worth kk I will deploy in it and if it works I will update it in the store.

  • 1

    Nothing, good luck with your app :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.