undo image in c#
<pre><code>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 &amp;&amp; _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;
   }

 }
</code></pre>

<p>When ResetBitmap() is called after rotation then it shows "Parameter is not valid". but if</p>

<p><strong>this.imageHandler.CurrentBitmap.Dispose();</strong>  is commented then works fine. But if Flip() method is called several times then "Out of memory" exception is shown.</p>

<p>How can I solve it?</p>
