일부 사진을 RAM으로 복사하려고하는데 메모리 부족 예외가 발생합니다. 이유는 모르겠지만 "정지" ". 그러나 "unfreeze"하는 방법과 이것이 정말로 문제입니까?메모리 부족 예외 C# freezable.freeze
public void preLoadThread(Object o)
{
Overlay ov = (Overlay)o;
ImageSource tempNext = BitmapConverter(ov.tempPreLoadPathNext);
ImageSource tempPrev = BitmapConverter(ov.tempPreLoadPathPrev);
tempNext.Freeze();
tempPrev.Freeze();
ov.Dispatcher.Invoke(
DispatcherPriority.Normal,
(Action)delegate()
{
ov.preLoadedNext = tempNext;
ov.preLoadedPrev = tempPrev;
ov.preLoadPathNext = ov.tempPreLoadPathNext;
ov.preLoadPathPrev = ov.tempPreLoadPathPrev;
}
);
}
public BitmapSource BitmapConverter(String path)
{
System.Drawing.Bitmap b = null;
using (FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.ReadWrite))
{
try
{
b = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(fs);
}
catch (Exception)
{
GC.Collect();
GC.WaitForFullGCComplete();
}
fs.Close();
}
if (b == null)
{
// Error
return null;
}
BitmapSizeOptions options = BitmapSizeOptions.FromEmptyOptions();
BitmapSource bs = null;
try
{
bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
b.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
options);
}
catch (Exception)
{
GC.Collect();
GC.WaitForFullGCComplete();
}
return bs;
}
GC.Collect를가 해답이 될 수 없습니다 ... 옵션을 선택하지 않습니다. –
나는이 누출을 고칠 수있는 단서가 없기 때문에 시도 및 오류가 발생했습니다. – Martin
작업하려는 이미지의 크기는 얼마나됩니까? –