두 개의 양식 A와 B가 있습니다. 양식 A에서 단추를 클릭하고 양식 B에있는 PictureBox에 이미지를로드하고 있습니다. 그리고이 이미지로 GrayScale을 설정하려고합니다 :GrayScale (ColorMatrix 기준)은 OutOfMemoryException을 발생시킵니다. 왜?
public void SetGrayScale(PictureBox pb)
{
ColorMatrix matrix = new ColorMatrix(new float[][]
{
new float[] {0.299f, 0.299f, 0.299f, 0, 0},
new float[] {0.587f, 0.587f, 0.587f, 0, 0},
new float[] {0.114f, 0.114f, 0.114f, 0, 0},
new float[] { 0, 0, 0, 1, 0},
new float[] { 0, 0, 0, 0, 0}
});
Image image = (Bitmap)pb.Image.Clone();
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(matrix);
Graphics graphics = Graphics.FromImage(image);
graphics.DrawImage(image,
new Rectangle(0, 0, image.Width, image.Height),
0,
0,
image.Width,
image.Height,
GraphicsUnit.Pixel,
attributes);
graphics.Dispose();
pb.Image = image;
}
이 코드는 PictureBox가 같은 양식 (A)에있을 때 제대로 작동합니다. 그러나 Form B에있을 때 OutOfMemoryException이 발생합니다. 왜 ?
어디에서 OutOfMemoryException이 발생합니까? – ChrisF
이미지가 pb 크기가 얼마나 큽니까? –
@ 토니 : 매번 새로운 답변을 추가하는 대신 의견을 추가하여 질문이나 다른 답변에 대한 질문에 답변해야합니다. – OregonGhost