2013-02-06 2 views
0

저는 C#에서 이미지 처리에 비교적 익숙하지 않습니다. 그림 상자에서이 동적으로 구성된 BMP의 크기를 조정하려고 시도하지만 이미지의 크기가 전혀 조정되지 않습니다. BMP가 그림 상자 전체를 채우기를 원합니다. 그림 상자는 555 x 555입니다. BMP가 원래 크기 (100 x 100)로 표시됩니다. 어떤 아이디어?그림 상자에서 이미지가 늘어나지 않는 이유는 무엇입니까?

private void Form1_Load(object sender, EventArgs e) 
{ 
    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; 
} 

private void pictureBox1_Paint(object sender, PaintEventArgs e) 
{ 
    Graphics gPB = e.Graphics; 

    Bitmap bmp = new Bitmap(100, 100); 
    Graphics gBmp = Graphics.FromImage(bmp); 


    Brush whiteBrush = new SolidBrush(Color.White); 
    gBmp.FillRectangle(whiteBrush, 0, 0, bmp.Width, bmp.Height); 

    Brush redBrush = new SolidBrush(Color.IndianRed); 
    gBmp.FillRectangle(redBrush, 0, 0, 20f, 20f); 

    Brush greenBrush = new SolidBrush(Color.MediumSeaGreen); 
    gBmp.FillRectangle(greenBrush, 20, 0, 20f, 20f); 

    Brush blueBrush = new SolidBrush(Color.MediumSlateBlue); 
    gBmp.FillRectangle(blueBrush, 0, 20, 20f, 20f); 

    Brush yellowBrush = new SolidBrush(Color.LightYellow); 
    gBmp.FillRectangle(yellowBrush, 20, 20, 20f, 20f); 

    gPB.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height); 

    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; 
} 

나는 또한 Zoom SizeMode를 시도했다. 그것은 아무런 효과가 없었습니다.

답변

2

.NET의 Interpolation 속성을 활용할 수 있습니다. 여기를 참조하십시오 : http://msdn.microsoft.com/en-us/library/system.drawing.graphics.interpolationmode.aspx

gPB.InterpolationMode = InterpolationMode.NearestNeighbor; 
gPB.DrawImage(bmp, 0, 0, 555, 555); 
+0

흥미 롭군요. 나는 이미지를 그릴 때 pictureBox의 너비와 높이를 사용하는 것을 결코 생각하지 못했습니다. 보간 모드는 크기를 조정 한 후 해상도를 높이는 데 도움이됩니다. 그게 내가 원하는거야! – deutschZuid

관련 문제