0
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()在循环后调用时,它显示“参数无效”。但如果在c#中撤消图像
this.imageHandler.CurrentBitmap.Dispose();被评论,然后正常工作。但是如果多次调用Flip()方法,则会显示“内存不足”异常。
我该如何解决?