How to take snapshot (screenshot) using asp.net (C#, VB)

Introduction: In this article I will explain how to take snapshot/screenshot of desktop or a particular open window using asp.net (C#, VB)

Description:
 take snapshot




Html Markup Of page:
<asp:Button ID="Button1" runat="server" Text="Take ScreenShot" onclick="Button1_Click"/>

Note: - First of all we have to add the reference of System.Windows.Forms library.

C# Code:
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Drawing;

    protected void Button1_Click(object sender, EventArgs e)
    {      
        Capture("E:/SS/" + Guid.NewGuid() + "ScreenShot.png");
    }
    public static void Capture(string CapturedScreenShot)
    {
        try
        {
            Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            Graphics graphics = Graphics.FromImage(bitmap as System.Drawing.Image);
            graphics.CopyFromScreen(5, 5, 5, 5, bitmap.Size);
            bitmap.Save(CapturedScreenShot, ImageFormat.Png);
        }
        catch (Exception ex)
        {
        }
    }

VB Code:
Imports System.Drawing.Imaging
Imports System.Drawing
Imports System.Windows.Forms

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Capture("E:/SS/" & Convert.ToString(Guid.NewGuid()) & "ScreenShot.png")
    End Sub
    Public Shared Sub Capture(ByVal CapturedScreenShot As String)
        Try
            Dim bitmap As New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
            Dim graphics__1 As Graphics = Graphics.FromImage(TryCast(bitmap, System.Drawing.Image))
            graphics__1.CopyFromScreen(5, 5, 5, 5, bitmap.Size)
            bitmap.Save(CapturedScreenShot, ImageFormat.Png)
        Catch ex As Exception
        End Try

    End Sub

Is this article helpful for you?

If yes post your comment to appreciate my work and fell free to contact me. You can like me on Facebook, Google+, Linkedin and Twitter via hit on Follow us Button and also can get update follow by Email.

Post a Comment

hot to store that taken screenshot on sql database plz help me i want to store taken screenshot into database

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget