2012-04-06 2 views
2

이 기능을 사용하여 이미지를 여러 번 회전하면 오류 메시지 "메모리 부족"이 표시됩니다. C# .net 4 이미지를 래터 레이트하려면 ImageFunctions.dll을 사용했습니다. DLL을 Decompiling 나는 다음과 같은있어. 회전 이미지에 "메모리 부족"예외가 표시됨

은 전체 코드의 일부는이
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

로직을 자세히 분석하지는 않았지만 비트 맵 클래스를 삭제해야합니다. 비트 맵 인스턴스는 적절한 곳에 배치하십시오. –

답변

3

클라우디오 (Claudio)가 언급했듯이, 사용하지 않은 것을 폐기해야합니다 (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); 
    this.imageHandler.CurrentBitmap = bitmap; 
} 
+0

this.imageHandler.CurrentBitmap.Dispose()는 메모리를 해제하지만 다른 예외 (매개 변수가 유효하지 않음)를 만듭니다. 세부 사항을보십시오 http://stackoverflow.com/questions/10177414/undo-image-in-c-sharp – learner

3

이 왜 대신 복사본을 만드는, 현재 비트 맵을 회전 :

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 class RotationHandler 
{ 
    private ImageHandler imageHandler; 

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

+1 Youre 이렇게 게으른 : P – SwDevMan81

+0

넵, thats me :) –

관련 문제