C# LockScreen.SetImageUri参数异常,尽管有工作Uri

C# LockScreen.SetImageUri参数异常,尽管有工作Uri,c#,windows-phone-8,C#,Windows Phone 8,我很难将锁屏设置为图像,但我认为这不是Uri的问题,而是图像本身的问题 当我尝试将图像设置为一个下载的图像,该图像的大小与锁屏的大小大致相同时,也可以在图像不太大的情况下工作。但是,当我试图将锁屏图像设置为诺基亚Lumia 920相机拍摄的照片时,它给了我一个例外 我的代码: //从StorageHelper类: public async Task<bool> SavePhotoAsync(Photo photo, WriteableBitmap source, int height

我很难将锁屏设置为图像,但我认为这不是Uri的问题,而是图像本身的问题

当我尝试将图像设置为一个下载的图像,该图像的大小与锁屏的大小大致相同时,也可以在图像不太大的情况下工作。但是,当我试图将锁屏图像设置为诺基亚Lumia 920相机拍摄的照片时,它给了我一个例外

我的代码:

//从StorageHelper类:

public async Task<bool> SavePhotoAsync(Photo photo, WriteableBitmap source, int height, int width)
    {
        return await Task.Run(() =>
            {
                try
                {
                    lock (StorageLock)
                    {
                        ObservableCollection<Photo> observableCollection = photo.PhotoAlbum.Photos as ObservableCollection<Photo>;
                        if (observableCollection == null)
                        {
                            return false;
                        }

                        if (!IsolatedStorageFile.GetUserStoreForApplication().DirectoryExists(photo.PhotoAlbum.Name))
                        {
                            IsolatedStorageFile.GetUserStoreForApplication().CreateDirectory(photo.PhotoAlbum.Name);
                        }

                        string fileName = photo.PhotoAlbum.Name + "/" + observableCollection.IndexOf(photo).ToString(CultureInfo.InvariantCulture);
                        if (IsolatedStorageFile.GetUserStoreForApplication().FileExists(fileName))
                        {
                            IsolatedStorageFile.GetUserStoreForApplication().DeleteFile(fileName);
                        }

                        IsolatedStorageFileStream fileStream =
                            IsolatedStorageFile.GetUserStoreForApplication().CreateFile(fileName);

                        int targetWidth = 0;
                        int targetHeight = 0;
                        if (source.PixelWidth < width || source.PixelHeight < height)
                        {
                            targetWidth = source.PixelWidth;
                            targetHeight = source.PixelHeight;
                        }
                        else
                        {
                            if (source.PixelWidth > source.PixelHeight)
                            {
                                double percentage = ((double)height)/((double) source.PixelHeight);
                                targetHeight = height;
                                targetWidth = (int) (source.PixelWidth * percentage);
                            }
                            else
                            {
                                double percentage = ((double)width) / ((double)source.PixelWidth);
                                targetWidth = width;
                                targetHeight = (int)(source.PixelHeight * percentage);
                            }
                        }

                        source.SaveJpeg(fileStream, targetWidth, targetHeight, 0, 100);

                        fileStream.Close();
                        return true;
                    }
                }
                catch (Exception e)
                {
                    return false;
                }

            });
    }
//StorageHelper的结尾

//从我的LockscreenManager课程:

public static async void SetLockScreenImages()
    {
        LockScreenRequestResult result = await LockScreenManager.RequestAccessAsync();
        if (result == LockScreenRequestResult.Granted)
        {
            Uri uri = null;
            try
            {
                uri = LockScreen.GetImageUri();
            }
            catch (Exception)
            {

            }

            List<Uri> uriList = await BuildUriList();
            if (uriList.Count == 0)
            {
                return;
            }

            int index = 0;
            if (uri != null && uriList.Any(uriEntry => uri.ToString() == uriEntry.ToString()))
            {
                index = (uriList.IndexOf(uri) + 1) % uriList.Count;
            }

            if (InterfaceProvider.GetIStorageService().FileExists(uriList[index]))
            {
                try
                {
                    LockScreen.SetImageUri(uriList[index]);
                }
                catch (Exception)
                {

                }

            }
        }
    }
//Lockscreenmanager类结束


你可以忽略我缩小图像的尝试,这没有帮助,但图像仍然正确保存。我能做什么?

异常消息是什么?System.ArgumentException:值不在预期范围内。遗憾的是,没有内部异常或其他东西表明您使用了正确的模式?如果它不是应用程序包的一部分,则需要有ms-appdata:///Local/ prefixDid你能解决这个问题吗?