런타임시 이미지 크기 조정을 위해 .net dll (http://imageresizing.net/download)을 사용하고 있습니다. 그것은 완벽하게 작동합니다. 그러나, (1-7 사이의 일) 잠시 후 발생하는 시스템은 심지어 뷰어에서 예외를 발생하기 시작 :OutOfMemoryException in Image Resizing
예외 정보 : 예외 유형 :에서 OutOfMemoryException 예외 메시지 : 메모리가 부족하여 프로그램의 실행을 계속합니다 .
그런 예외가 발생하면 웹 사이트는 일반적으로 "System.OutOfMemoryException"을 던지는 오류로 인해 작업을 중단합니다.
웹 사이트가 실행되는 응용 프로그램 풀을 "재활용"하면 코드가 변경되지 않고 문제가 해결되고 웹 사이트가 즉시 정상 상태로 돌아갑니다.
dll을 이미지 처리하기 전에 우리는 사용자 정의 코드를 사용하고 있었고 같은 문제가 발생했습니다. 다음은 코드입니다.
private Bitmap ConvertImage(Bitmap input, int width, int height, bool arc)
{
if (input.PixelFormat == PixelFormat.Format1bppIndexed ||
input.PixelFormat == PixelFormat.Format4bppIndexed ||
input.PixelFormat == PixelFormat.Format8bppIndexed)
{
Bitmap unpackedBitmap = new Bitmap(input.Width, input.Height);
Graphics g = Graphics.FromImage(unpackedBitmap);
g.Clear(Color.White);
g.DrawImage(input, new Rectangle(0,0,input.Width, input.Height));
g.Dispose();
input = unpackedBitmap;
}
double aspectRatio = (double)input.Height/(double)input.Width;
int actualHeight = CommonMethods.GetIntValue(Math.Round(aspectRatio * width, 0));
Bitmap _imgOut;
if (actualHeight > height)
{
ResizeImage resizeImage = new ResizeImage(width, actualHeight, InterpolationMethod.Bicubic);
Bitmap _tempBitmap = resizeImage.Apply(input);
Bitmap _croppedBitmap = new Bitmap(width, height);
Graphics _crop = Graphics.FromImage(_croppedBitmap);
_crop.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
_crop.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
_crop.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
_crop.DrawImageUnscaledAndClipped(_tempBitmap, new Rectangle(0, 0, width, height));
_crop.Dispose();
_imgOut = _croppedBitmap;
}
else
{
ResizeImage resizeImage = new ResizeImage(width, height, InterpolationMethod.Bicubic);
_imgOut = resizeImage.Apply(input);
}
// Draw the arc if it has been requested
if (arc)
{
Graphics _arc = Graphics.FromImage(_imgOut);
_arc.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
_arc.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
_arc.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
_arc.DrawArc(new Pen(Color.White, 24), new Rectangle(-13, -13, 50, 50), 180, 90);
_arc.Dispose();
}
// job done
return _imgOut;
}
우리는 크기를 조정하는 이미지처럼 : www.mysite.com/images/myimage.jpg?width=196 & 높이 = 131
는 기대. Farrukh
얼마나 많은 RAM을 사용할 수 있습니까? 메모리 조각화는 메모리 누수가 발생하지 않더라도 사용 가능한 큰 블록의 양을 줄일 수 있습니다. 시나리오를 지원할 수있는 충분한 RAM이 있는지 확인하는 가장 좋은 방법입니다. 또한 DiskCache 플러그인을 사용하고 있습니까? 그렇지 않다면 문제가 있습니다. –
답장을 보내 주셔서 감사합니다. 서버의 RAM 크기는 16GB이고 예. 우리는 imageresizer와 함께 DiskCache 플러그인을 사용하고 있습니다. –
여기에 2 가지 질문을하고 있습니다. 1) 내 코드에 무슨 문제가 있습니까? 2) 왜 ImageResizer에 문제가 있습니까? 아직도 이전 코드를 사용하고 있습니까? 그것은 많은 메모리 누수가 있습니다. –