Saving image to media library WP7

后端 未结 2 1464
甜味超标
甜味超标 2021-01-16 02:58

I cant save images into windows phone media library ! Here is my code snippet :

public void SaveImageTo(string fileName) 
    {
        fileName += \".jpg\";         


        
2条回答
  •  不知归路
    2021-01-16 03:53

    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!

提交回复
热议问题