:
private Image GetControlThumb(Control control, int thumbSize)
{
Bitmap imgLarge = new Bitmap(control.Bounds.Width, control.Bounds.Height);
using (Graphics g = Graphics.FromImage(imgLarge))
{
g.CopyFromScreen(
control.Parent.PointToScreen(new Point(control.Left, control.Top)),
new Point(0, 0),
new Size(control.Bounds.Width, control.Bounds.Height));
}
Size size;
if (control.Width > control.Height)
{
size = new Size(thumbSize, (int)(thumbSize * (float)control.Height/(float)control.Width));
}
else
{
size = new Size((int)(thumbSize * (float)control.Width/(float)control.Height), thumbSize);
}
Image imgSmall = imgLarge.GetThumbnailImage(size.Width, size.Height, new Image.GetThumbnailImageAbort(delegate { return false; }), IntPtr.Zero);
imgLarge.Dispose();
return imgSmall;
}
당신이 얻을하는 데 사용할 수 있습니다 다음과 같은 컨트롤의 축소판 그림 :
버튼을 클릭하면 디스크에 이미지를 저장할 수 있지만 사용자 컨트롤 laod에서는 흰색 이미지가 나타나며 그림판()을 사용할 수 있습니까? 이것은 사용자 정의 컨트롤에서 여러 번 호출됩니다. –
Using 블록의 목적은 무엇입니까? –
Graphics 클래스는 IDisposable을 구현합니다. using 블록은 Dispose 메서드가 호출되어 Graphics 객체가 리소스를 해제 할 수 있도록합니다. –