[C#] 캡쳐 소스

public Bitmap[] Capture( CaptureType typeOfCapture )
{
    // used to capture then screen in memory
    Bitmap memoryImage;
    // number of screens to capture,
    // will be updated below if necessary
    int count = 1;

    try
    {
        Screen[] screens = Screen.AllScreens;
        Rectangle rc;

        // setup the area to capture
        // depending on the supplied parameter
        switch ( typeOfCapture )
        {
            case CaptureType.PrimaryScreen:
                rc = Screen.PrimaryScreen.Bounds;
                break;
            case CaptureType.VirtualScreen:
                rc = SystemInformation.VirtualScreen;
                break;
            case CaptureType.WorkingArea:
                rc = Screen.PrimaryScreen.WorkingArea;
                break;
            case CaptureType.AllScreens:
                count = screens.Length;
                typeOfCapture = CaptureType.WorkingArea;
                rc = screens[0].WorkingArea;
                break;
            default:
                rc = SystemInformation.VirtualScreen;
                break;
        }
        // allocate a member for saving the captured image(s)
        images = new Bitmap[count];

        // cycle across all desired screens
        for ( int index = 0; index < count; index++ )
        {
            if ( index > 0 )
                rc = screens[index].WorkingArea;
                // redefine the size on multiple screens

            memoryImage = new Bitmap( rc.Width, rc.Height, 
                          PixelFormat.Format32bppArgb );
            using ( Graphics memoryGrahics = 
                    Graphics.FromImage( memoryImage ) )
            {
                // copy the screen data
                // to the memory allocated above
                memoryGrahics.CopyFromScreen( rc.X, rc.Y, 
                   0, 0, rc.Size, CopyPixelOperation.SourceCopy );
            }
            images[index] = memoryImage;
            // save it in the class member for later use
        }
    }
    catch ( Exception ex )
    {
        // handle any erros which occured during capture
        MessageBox.Show( ex.ToString(), "Capture failed", 
            MessageBoxButtons.OK, MessageBoxIcon.Error );
    }
    return images;
}
출처 : http://www.codeproject.com/KB/graphics/ScreenCaptureByHolzhauer.aspx

'프로그램 경험 > .Net' 카테고리의 다른 글

[VisualStudio] 실전 빌드 이벤트  (0) 2010.01.13
[.Net] 보호된 메모리를 읽거나 쓰려고 했습니다...  (2) 2009.12.09
[C#] 캡쳐 소스  (0) 2009.12.08
[C#] PC의 IP 변경하기  (0) 2009.10.29
[C#] PC의 IP주소 얻기  (0) 2009.09.17
[C#] DateTime 비교  (0) 2009.09.10

Trackbacks 0 / Comments 0

티스토리 툴바