2012-04-06 21 views
2

この機能を使用してイメージを数回(5以上)回転させると、エラーメッセージ 「メモリ不足」が表示されます。 c#.net 4でイメージをラトレートするにはImageFunctions.dllを使用しました。 DLLの逆コンパイル私は次のことがあります。回転イメージに「メモリ不足」例外が表示される

は全体のコードの一部は、それが回転

私はそれを解決するにはどうすればよい
public class RotationHandler 
{ 
    private ImageHandler imageHandler; 

    public void Flip(RotateFlipType rotateFlipType) 
    { 
     this.imageHandler.RestorePrevious(); 
     Bitmap bitmap = (Bitmap) this.imageHandler.CurrentBitmap.Clone(); 
     bitmap.RotateFlip(rotateFlipType); 
     this.imageHandler.CurrentBitmap = (Bitmap) bitmap.Clone(); 
    } 
} 

のために使用されて与えられていますか?

次の方法はlazyberezovskyが提案したように問題を解決します。

public void Flip(RotateFlipType rotateFlipType) 
    { 
    this.imageHandler.RestorePrevious(); 
    this.imageHandler.CurrentBitmap.RotateFlip(rotateFlipType); 
} 

しかし、輝度法の別の問題。

public void SetBrightness(int brightness) 
    { 
     Bitmap temp = (Bitmap)_currentBitmap; 

      Bitmap bmap = (Bitmap)temp.Clone(); 
      if (brightness < -255) brightness = -255; 
      if (brightness > 255) brightness = 255; 
      Color c; 
      for (int i = 0; i < bmap.Width; i++) 
      { 
       for (int j = 0; j < bmap.Height; j++) 
       { 
        c = bmap.GetPixel(i, j); 
        int cR = c.R + brightness; 
        int cG = c.G + brightness; 
        int cB = c.B + brightness; 

        if (cR < 0) cR = 1; 
        if (cR > 255) cR = 255; 

        if (cG < 0) cG = 1; 
        if (cG > 255) cG = 255; 

        if (cB < 0) cB = 1; 
        if (cB > 255) cB = 255; 

        bmap.SetPixel(i, j, Color.FromArgb((byte)cR, (byte)cG, (byte)cB)); 
       } 
      } 
      _currentBitmap = (Bitmap)bmap.Clone(); 


    } 

この方法は、いくつかの画像のために動作し、他の画像では動作せず、次のエラー 示す「とsetPixelをインデックス付きピクセルフォーマットの画像のためにサポートされていません。」

ローテーション、トリミング、および明るさのための効率的で実用的な方法を提供できると非常に役に立ちます。 もう一度お手伝いください。

+0

ロジックを詳細に分析していませんが、ビットマップクラスを処理する必要があります。 Bitmapインスタンスを有効にした場所に配置します。 –

答えて

3

クラウディオには、使用していないBitmapsを処分していることを確認する必要があります。

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); 
    Bitmap clone_map = (Bitmap) bitmap.Clone(); 
    bitmap.Dipose(); // dispose of original cloned Bitmap 
    this.imageHandler.CurrentBitmap = clone_map; 
} 

あなたはおそらくこれを簡素化することができます:

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; 
} 
+0

this.imageHandler.CurrentBitmap.Dispose()はメモリを解放しますが、別の例外を作成します(パラメータは無効です)。詳細を参照してくださいhttp://stackoverflow.com/questions/10177414/undo-image-in-c-sharp – learner

3

代わりにコピーを作成するのではなく、現在のビットマップを回転させないのはなぜ?

public class RotationHandler 
{ 
    private ImageHandler imageHandler; 

    public void Flip(RotateFlipType rotateFlipType) 
    { 
     this.imageHandler.RestorePrevious(); 
     this.imageHandler.CurrentBitmap.RotateFlip(rotateFlipType); 
    } 
} 
+0

+1 Youreとても怠惰:P – SwDevMan81

+0

うん、それは私です:) –

関連する問題