asp.net with c#

컨트롤 캡쳐

damian 2012. 1. 10. 10:20

// 컨트롤 캡쳐관련 클래스
public class win32
{
  [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]


  private static extern bool BitBlt (
      IntPtr hdcDest, // handle to destination DC
      int nXDest,  // x-coord of destination upper-left corner
      int nYDest,  // y-coord of destination upper-left corner
      int nWidth,  // width of destination rectangle
      int nHeight, // height of destination rectangle
      IntPtr hdcSrc,  // handle to source DC
      int nXSrc,   // x-coordinate of source upper-left corner
      int nYSrc,   // y-coordinate of source upper-left corner
      System.Int32 dwRop  // raster operation code
  );

  [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]

  private static extern IntPtr  CreateDC(
      string lpszDriver,        // driver name
      string lpszDevice,        // device name
      string lpszOutput,        // not used; should be NULL
      IntPtr lpInitData   // optional printer data
  );

  public static bool CaptureWindow(System.Windows.Forms.Control control, ref System.Drawing.Bitmap bitmap)
  {
      Graphics g2 = Graphics.FromImage(bitmap);
      IntPtr dc1 = CreateDC("DISPLAY", null, null, (IntPtr)null);
      IntPtr dc2 = g2.GetHdc();

      Point APoint = control.PointToScreen(new Point(0, 0));
      BitBlt(dc2, 0, 0, control.Width, control.Height, dc1, APoint.X, APoint.Y, 13369376);
 
      g2.ReleaseHdc(dc1);
      g2.Dispose();

      return true;
  }

}

//컨트롤 캡쳐 매서드
private void swf2jpg()
{
   Bitmap bitmap = new Bitmap(flash.Width, flash.Height);  //플래쉬의 가로,새로

   win32.CaptureWindow(flash, ref bitmap);

   bitmap.Save(Application.StartupPath + @"\work\report.jpg");    //저장경로
}


'asp.net with c#' 카테고리의 다른 글

c# 연산자  (0) 2012.02.01
DataTable에 PrimaryKey 설정  (0) 2012.01.10
DataTable Merge  (0) 2012.01.10
DataTable 중복된 값 제거  (0) 2012.01.10
DataTable 가로 세로 변환  (0) 2012.01.10