私のアプリケーションでは、以下のヘルパー メソッドを使用して、Isolated ストレージ イメージを Image コントロールにバインドしています。このヘルパー メソッドは、リンク「分離ストレージに保存されているイメージを Windows Phone のイメージ コントロールにバインドする」から取得しました。
public class IsoStoreImageSource : DependencyObject
{
public static void SetIsoStoreFileName(UIElement element, string value)
{
element.SetValue(IsoStoreFileNameProperty, value);
}
public static string GetIsoStoreFileName(UIElement element)
{
return (string)element.GetValue(IsoStoreFileNameProperty);
}
// Using a DependencyProperty as the backing store for IsoStoreFileName. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsoStoreFileNameProperty =
DependencyProperty.RegisterAttached("IsoStoreFileName", typeof(string), typeof(IsoStoreImageSource), new PropertyMetadata("", Changed));
private static void Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Image img = d as Image;
if (img != null)
{
var path = e.NewValue as string;
SynchronizationContext uiThread = SynchronizationContext.Current;
Task.Factory.StartNew(() =>
{
using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isoStore.FileExists(path))
{
var stream = isoStore.OpenFile(path, System.IO.FileMode.Open, FileAccess.Read);
uiThread.Post(_ =>
{
var _img = new BitmapImage();
_img.SetSource(stream);
img.Source = _img;
}, null);
}
}
});
}
}
}
これを ListBox コントロール内で使用しています。デフォルトのライブラリ イメージを試してみると、すべてが期待どおりに機能します。しかし、大きなサイズの画像(デバイスのカメラで撮影したもの)を試してみると、アプリがクラッシュします。
そして、ここに私が得ている例外があります
タイプ 'System.OutOfMemoryException' の例外が System.Windows.ni.dll で発生しましたが、ユーザー コードで処理されませんでした
スタックトレース
MS.Internal.FrameworkCallbacks.NotifyManagedDebuggerOnNativeOOM() で MS.Internal.XcpImports.BitmapSource_SetSource(BitmapSource bitmapSource, CValue& byteStream) で System.Windows.Media.Imaging.BitmapSource.SetSourceInternal(ストリーム streamSource) で System.Windows.Media.Imaging. MyaPP.Common.IsoStoreImageSource.<>c__DisplayClass4.<>c__DisplayClass6.b__1(Object _) の System.Windows.Media.Imaging.BitmapSource.SetSource(ストリーム streamSource) の BitmapImage.SetSourceInternal(ストリーム streamSource)