我有以下两个课程:
public class ImageHandler
{
private Bitmap _currentBitmap;
private Bitmap _bitmapbeforeProcessing;
public Bitmap CurrentBitmap
{
get
{
if (_currentBitmap == null)
{
_currentBitmap = new Bitmap(1, 1);
}
return _currentBitmap;
}
set { _currentBitmap = value; }
}
public string CurrentBitmapPath { get; set; }
public void ResetBitmap()
{
if (_currentBitmap != null && _bitmapbeforeProcessing != null)
{
Bitmap temp = (Bitmap)_currentBitmap.Clone();
_currentBitmap = (Bitmap)_bitmapbeforeProcessing.Clone();
_bitmapbeforeProcessing = (Bitmap)temp.Clone();
}
}
internal void RestorePrevious()
{
_bitmapbeforeProcessing = _currentBitmap;
}
}
和:
public class RotationHandler
{
private ImageHandler imageHandler;
public void Flip(RotateFlipType rotateFlipType)
{
this.imageHandler.RestorePrevious();
Bitmap bitmap = (Bitmap) this.imageHandler.CurrentBitmap.Clone();
this.imageHandler.CurrentBitmap.Dispose(); // dispose of current bitmap
bitmap.RotateFlip(rotateFlipType);
this.imageHandler.CurrentBitmap = bitmap;
}
}
ResetBitmap()
旋转后调用时,显示:
参数无效
但如果:
this.imageHandler.CurrentBitmap.Dispose();
被评论然后它工作正常。但是,如果Flip()
多次调用方法,则会发生 Out Of Memory 异常。
我该如何解决?