Click here to Skip to main content
15,885,916 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi,
I am making a Windows Phone Application where i need to save a picture to gallery. I am using the following code. the imgview is the image
But I am getting an Debugg error at
C#
var picture = mediaLibrary.SavePicture(fileName, stream);
. the filename which i am passing is correct. Do i need to add eny more assemblies or dll files to make that .. PlZ help me .

C#
private bool SaveImageToPhotoHub(WriteableBitmap bmp)
        {

            using (var mediaLibrary = new MediaLibrary())
            {
                using (var stream = new MemoryStream())
                {
                    var fileName = string.Format("Gs{0}.jpg", Guid.NewGuid());
                    bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
                    stream.Seek(0, SeekOrigin.Begin);
                    var picture = mediaLibrary.SavePicture(fileName, stream);
                    if (picture.Name.Contains(fileName)) return true;
                }
            }
            return false;
        }

        private void Save_Click(object sender, RoutedEventArgs e)
        {
            WriteableBitmap bmp = new WriteableBitmap(imgview, null);
            if (SaveImageToPhotoHub(bmp))
            {
                MessageBox.Show("Image Saved", "Information", MessageBoxButton.OK);
            }
            else
            {
                MessageBox.Show("Error : Image Not Saved", "Information", MessageBoxButton.OK);
            }
        }
Posted
Comments
Style-7 23-Apr-15 6:00am    
Windows Phone 7 or 8?
Style-7 23-Apr-15 6:02am    
See also permissons in manifest file.
And for 8
https://msdn.microsoft.com/en-us/library/windows/apps/dn376408.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900