Desktop picture Capture Source Code

Embed Size (px)

Citation preview

  • 8/14/2019 Desktop picture Capture Source Code

    1/3

  • 8/14/2019 Desktop picture Capture Source Code

    2/3

    //Downloaded from

    /Visual C# Kicks - http://vckicks.110mb.cong System;ng System.Collections.Generic;ng System.ComponentModel;ng System.Data;ng System.Drawing;ng System.Text;ng System.Windows.Forms;ng System.Runtime.InteropServices; //Needed

    space ScreenShotTaker

    publicpartialclassForm1 : Form{public Form1(){

    InitializeComponent();}

    privatevoid btnTake_Click(object sender, EventArgs e){

    pictureBox1.Image = ScreenShot.take();}

    privatevoid btnSave_Click(object sender, EventArgs e){

    if (saveFileDialog1.ShowDialog() == DialogResult.OK){

    pictureBox1.Image.Save(saveFileDialog1.FileName,em.Drawing.Imaging.ImageFormat.Bmp);

    }}

    }

    internalclassAPI{

    [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]publicstaticexternIntPtr GetDC(IntPtr hWnd);

    [DllImport("user32.dll", ExactSpelling = true)]publicstaticexternIntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);

    [DllImport("gdi32.dll", ExactSpelling = true)]publicstaticexternIntPtr BitBlt(IntPtr hDestDC, int x, int y, int nWidth, int nHeight

    Ptr hSrcDC, int xSrc, int ySrc, int dwRop);

    [DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]publicstaticexternIntPtr GetDesktopWindow();

    }

    internalclassScreenShot{

    publicstaticBitmap take(){

    int screenWidth = Screen.PrimaryScreen.Bounds.Width;

  • 8/14/2019 Desktop picture Capture Source Code

    3/3

    int screenHeight = Screen.PrimaryScreen.Bounds.Height;

    Bitmap screenBmp = newBitmap(screenWidth, screenHeight);Graphics g = Graphics.FromImage(screenBmp);

    IntPtr dc1 = API.GetDC(API.GetDesktopWindow());IntPtr dc2 = g.GetHdc();

    //Main drawing, copies the screen to the bitmapAPI.BitBlt(dc2, 0, 0, screenWidth, screenHeight, dc1, 0, 0, 13369376); //last number

    copy constant

    //Clean up

    API.ReleaseDC(API.GetDesktopWindow(), dc1);g.ReleaseHdc(dc2);g.Dispose();

    return screenBmp;}

    }}