ロック画面を画像に設定できなくて困っていますが、ウリではなく画像自体の問題だと思います。
画像をロック画面にほぼ適切なサイズのダウンロード画像に設定しようとすると、画像が大きすぎない場合にも機能します。しかし、ロック画面の画像をカメラ (Nokia 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 クラスの終わり
画像を縮小しようとする私の試みを無視してもかまいませんが、役に立ちませんでした (ただし、画像はまだ正しく保存されています)。どうすればよいですか?