■ Control 클래스를 사용해 컨트롤의 비트맵을 구하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
using System.Drawing; using System.Windows.Forms; #region 비트맵 구하기 - GetBitmap(sourceControl, targetSize) /// <summary> /// 비트맵 구하기 /// </summary> /// <param name="sourceControl">소스 컨트롤</param> /// <param name="targetSize">타겟 크기</param> /// <returns>비트맵</returns> public Bitmap GetBitmap(Control sourceControl, Size targetSize) { Size formSize = sourceControl.Size; Rectangle rectangle = new Rectangle(new Point(0, 0), formSize); Bitmap sourceBitmap = new Bitmap(formSize.Width, formSize.Height); sourceControl.DrawToBitmap(sourceBitmap, rectangle); Bitmap targetBitmap = new Bitmap(targetSize.Width, targetSize.Height); Graphics targetGraphics = Graphics.FromImage(targetBitmap); rectangle.Size = targetSize; targetGraphics.DrawImage(sourceBitmap, rectangle); return targetBitmap; } #endregion |