Desktop Picture Capture Source Code

  • Uploaded by: Nikola Lukic
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Desktop Picture Capture Source Code as PDF for free.

More details

  • Words: 201
  • Pages: 3
//Downloaded from //Visual C# Kicks - http://vckicks.110mb.com/ using using using using using using using using

System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Text; System.Windows.Forms; System.Runtime.InteropServices; //Needed

namespace ScreenShotTaker { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnTake_Click(object sender, EventArgs e) { pictureBox1.Image = ScreenShot.take(); } private void btnSave_Click(object sender, EventArgs e) { if (saveFileDialog1.ShowDialog() == DialogResult.OK) { pictureBox1.Image.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp); } } } internal class API { [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)] public static extern IntPtr GetDC(IntPtr hWnd); [DllImport("user32.dll", ExactSpelling = true)] public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC); [DllImport("gdi32.dll", ExactSpelling = true)] public static extern IntPtr BitBlt(IntPtr hDestDC, int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int dwRop);

}

[DllImport("user32.dll", EntryPoint = "GetDesktopWindow")] public static extern IntPtr GetDesktopWindow();

internal class ScreenShot { public static Bitmap take() { int screenWidth = Screen.PrimaryScreen.Bounds.Width;

int screenHeight = Screen.PrimaryScreen.Bounds.Height; Bitmap screenBmp = new Bitmap(screenWidth, screenHeight); Graphics g = Graphics.FromImage(screenBmp); IntPtr dc1 = API.GetDC(API.GetDesktopWindow()); IntPtr dc2 = g.GetHdc(); //Main drawing, copies the screen to the bitmap API.BitBlt(dc2, 0, 0, screenWidth, screenHeight, dc1, 0, 0, 13369376); //last number is the copy constant //Clean up API.ReleaseDC(API.GetDesktopWindow(), dc1); g.ReleaseHdc(dc2); g.Dispose(); return screenBmp; }

} }

Related Documents

Source Code
July 2020 13
Source Code
June 2020 19
Source Code
May 2020 17
Subject Code Desktop
August 2019 25

More Documents from "Jason Bentley"