Trong ứng dụng của tôi, tôi đang sử dụng phương pháp trợ giúp được đề cập dưới đây để gắn hình ảnh lưu trữ Riêng biệt của tôi vào Điều khiển hình ảnh. Tôi nhận được phương pháp này helper từ liên kết "Binding Image stored in the Isolated Storage to Image Control in Windows Phone"Lỗi ứng dụng trong khi cố gắng ràng buộc Hình ảnh lưu trữ riêng biệt
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);
}
}
});
}
}
}
Tôi đang sử dụng này bên trong một điều khiển ListBox. Và nếu thử với hình ảnh thư viện mặc định, mọi thứ sẽ hoạt động như mong đợi. Nhưng nếu tôi thử với những hình ảnh có kích thước lớn (chụp qua camera của thiết bị) thì ứng dụng bị treo.
Và đây là ngoại lệ những gì tôi đang nhận được
Một ngoại lệ của loại 'System.OutOfMemoryException' xảy ra ở System.Windows.ni.dll nhưng không được xử lý theo mã người dùng
stack trace
tại MS.Internal.FrameworkCallbacks.NotifyManagedDebuggerOnNativeOOM() tại MS.Internal.XcpImports.BitmapSource_SetSource (BitmapSource bitmapSource, CValue & byteStream) tại System.Windows.Media.Imaging.BitmapSource.SetSourceInternal (stream suối ource) tại System.Windows.Media.Imaging.BitmapImage.SetSourceInternal (Stream streamSource) tại System.Windows.Media.Imaging.BitmapSource.SetSource (Stream streamSource) tại MyaPP.Common.IsoStoreImageSource. <> c__DisplayClass4. <> c__DisplayClass6.b__1 (Object _)
Bạn có bao nhiêu hình ảnh trong chế độ xem danh sách của mình? Họ lớn đến mức nào?Bạn có thể chạy phân tích bộ nhớ trên ứng dụng của bạn ('Debug -> Bắt đầu phân tích ứng dụng Windows Phone -> Profiling -> Memory' trong Visual Studio) và đăng kết quả của bạn không? – Haspemulator
Cố gắng sử dụng LongListSelector làm Danh sách Phẳng – Mahantesh
@Haspemulator: Vấn đề được đề cập ở đây "http://stackoverflow.com/questions/15700340/out-of-memory-exception-while-loading-images-from-isolated-storage" , "http://blogs.developpeur.org/kookiz/archive/2013/02/17/wpdev-memory-leak-with-bitmapimage.aspx", Cách tôi có thể giải quyết vấn đề này với việc triển khai của bạn. –