I cant save images into windows phone media library ! Here is my code snippet :
public void SaveImageTo(string fileName)
{
fileName += \".jpg\";
I changed Shishir's snippet to read extern url. This is my method :
public void SaveImageTo(string fileName = "SO.jpg")
{
string source = "http://i.stack.imgur.com/PIFN0.jpg";
Uri url;
if (Uri.TryCreate(source, UriKind.Absolute, out url))
{
WriteableBitmap wr;
BitmapImage img = new BitmapImage(url);
img.CreateOptions = BitmapCreateOptions.None;
// When image is ready, show must go on.
img.ImageOpened += (s, e) =>
{
wr = new WriteableBitmap((BitmapImage)s);
//fileName += ".jpg"; // we dont need that
var myStore = IsolatedStorageFile.GetUserStoreForApplication();
if (myStore.FileExists(fileName))
{
myStore.DeleteFile(fileName);
}
IsolatedStorageFileStream myFileStream = myStore.CreateFile(fileName);
//WriteableBitmap wr = img; // image source already given
wr.SaveJpeg(myFileStream, wr.PixelWidth, wr.PixelHeight, 0, 85);
myFileStream.Close();
// Create a new stream from isolated storage, and save the JPEG file to the media library on Windows Phone.
myFileStream = myStore.OpenFile(fileName, FileMode.Open, FileAccess.Read);
MediaLibrary library = new MediaLibrary();
//byte[] buffer = ToByteArray(qrImage);
library.SavePicture(fileName, myFileStream);
};
}
}
Dont forget to add ID_CAP_MEDIALIB_PHOTO in WMAppManifest.xml . I hope this can help too.
try this ....
public void SaveImageTo(string fileName = "ShareByQR.jpg")
{
fileName += ".jpg";
var myStore = IsolatedStorageFile.GetUserStoreForApplication();
if (myStore.FileExists(fileName))
{
myStore.DeleteFile(fileName);
}
IsolatedStorageFileStream myFileStream = myStore.CreateFile(fileName);
WritableBitmap wr = imageControl; // give the image source
wr.SaveJpeg(myFileStream, wr.PixelWidth, wr.PixelHeight, 0, 85);
myFileStream.Close();
// Create a new stream from isolated storage, and save the JPEG file to the media library on Windows Phone.
myFileStream = myStore.OpenFile(fileName, FileMode.Open, FileAccess.Read);
MediaLibrary library = new MediaLibrary();
//byte[] buffer = ToByteArray(qrImage);
library.SavePicture(fileName, myFileStream);
}
hope it works!