0

嗨,我正在开发一个锁屏应用程序,我正在使用图像列表框。在我单击按钮设置锁屏时选择图像后,它应该更新。但它是机器人更新。这是我的代码

private async void ApplicationBarIconButton_Click(object sender, EventArgs e)
    {
        MediaLibrary mediaLibrary = new MediaLibrary();
        //ImageSource im = image1.Source;
        BitmapImage bitmap = new BitmapImage();
        bitmap.SetSource(mediaLibrary.Pictures[imageList.SelectedIndex].GetImage());

        String tempJPEG = "MyWallpaper1.jpg";

        using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if (myIsolatedStorage.FileExists(tempJPEG))
            {
                myIsolatedStorage.DeleteFile(tempJPEG);
            }

            IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG);

            StreamResourceInfo sri = null;
            Uri uri = new Uri(tempJPEG, UriKind.Relative);
            sri = Application.GetResourceStream(uri);

            WriteableBitmap wb = new WriteableBitmap(bitmap);

            Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 90);

            fileStream.Close();
        }

        LockScreenChange(tempJPEG);

    }

    private async void LockScreenChange(string filePathOfTheImage)
    {
        if (!LockScreenManager.IsProvidedByCurrentApplication)
        {
            await LockScreenManager.RequestAccessAsync();
        }

        if (LockScreenManager.IsProvidedByCurrentApplication)
        {
            var schema = "ms-appdata:///Local/";
            var uri = new Uri(schema + filePathOfTheImage, UriKind.Absolute);

            LockScreen.SetImageUri(uri);
            var currentImage = LockScreen.GetImageUri();
            MessageBox.Show("Success", "LockScreen changed", MessageBoxButton.OK);
        }
        else
        {
            MessageBox.Show("Background cant be changed. Please check your permissions to this application.");
        }
    }

实际上,当第一次启动应用程序并单击设置按钮时,当前选择的图像设置为锁屏,之后当我选择另一个图像时,它显示锁屏已更改,成功。没有错误也没有异常。我没有知道问题出在哪里。请帮忙........

4

1 回答 1

0

它通过将临时文件名更改为原始文件名即字符串 tempJpeg 来解决

于 2014-01-31T07:19:52.567 回答