将图像添加到锁定屏幕C#

时间:2014-07-25 17:52:25

标签: c# image windows-phone-8 canvas isolatedstorage

我想要实现的是将我的画布保存为隔离存储中的图像,然后将该图像用作锁定屏幕。 问题是它只发生一次,之后当画布更新时,当我尝试用新图像更改锁定屏幕时,它不会更新。我尝试了以下代码:

Uri uri;
    async private void LockScreen_Click(object sender, EventArgs e)
    {
        bitmap = null;
        bitmap = new WriteableBitmap((int)bgCanvas.Width, (int)bgCanvas.Height);
        bitmap.Render(bgCanvas,null);
        bitmap.Invalidate();

        using(IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
        {
            //Delete old background file from isolated storage
            if (iso.FileExists("Background"))
            {
                iso.DeleteFile("Background");
            }
            //Save canvas to isolated storage 
            using (IsolatedStorageFileStream isostream = iso.CreateFile("Background"))
            {
                Extensions.SaveJpeg(bitmap, isostream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
                //isostream.Close();
            }            
        }
        //Access isolated storage file and put as lock screen
        try
        {
            var isProvider = Windows.Phone.System.UserProfile.LockScreenManager.IsProvidedByCurrentApplication;  
            if (!isProvider)
            {
                var permission = await Windows.Phone.System.UserProfile.LockScreenManager.RequestAccessAsync();
                isProvider = permission == Windows.Phone.System.UserProfile.LockScreenRequestResult.Granted;
            }
            if (isProvider)
            {
                uri = new Uri("ms-appdata:///Local/Background", UriKind.Absolute);
                Windows.Phone.System.UserProfile.LockScreen.SetImageUri(uri);
                MessageBox.Show("Lock Screen updated!");
            }
            else
            {
                MessageBox.Show("Couldn't update the lockscreen picture.");
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show("An error occured while updating the lockscreen picture: " + ex.Message);
        }

    }

消息框显示锁定屏幕已更新,即使它不是。 我认为文件没有在隔离存储中更新,但无法找出原因?

0 个答案:

没有答案