﻿Imports System.Drawing.Imaging
Imports ScreenShot
Imports System.Drawing

Partial Class TestPages_WindowTestPage
    Inherits System.Web.UI.Page

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim SC As New ScreenShot.ScreenCapture

        'grabs image of object handle (in this case, the form)
        Dim MyWindow As Image = SC.CaptureWindow(Me.handle)

        'grabs image of entire desktop
        Dim MyDesktop As Image = SC.CaptureScreen

        'captures entire desktop straight to file
        SC.CaptureScreenToFile("c:\desktop2.jpg", Imaging.ImageFormat.Jpeg)

        'captures image of object handle (in this case, the form) straight to file
        SC.CaptureWindowToFile(Me.Handle, "c:\window2.jpg", Imaging.ImageFormat.Jpeg)
        'returns bitmap of region of desktop by passing in a rectangle
        Dim MyBitMap As Bitmap = SC.CaptureDeskTopRectangle(New Rectangle(Me.Location.X, Me.Location.Y, Me.Width, Me.Height), Me.Width, Me.Height)
        MyBitMap.Save("../images/ScreenCaptures/test.bmp", Imaging.ImageFormat.Bmp)
        'above example gets rectangle of form that it is called in, you can get
        'desktop by calling me.hide before the actual function call in order to
        'get the desktop that is in the bounds of the form (handy when using a
        'transparent Form or control in order to make a "viewfinder" for the capture...)
        'You can pass in any rectangle you want, this was so you can see how
        'it works...
    End Sub

    'Dim ScreenSize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
    'Dim screenGrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim ScreenSize As Size = New Size(Windows.Forms.Screen.PrimaryScreen.Bounds.Width, Windows.Forms.Screen.PrimaryScreen.Bounds.Height)
        Dim ObjBitmap As New Bitmap(Windows.Forms.Screen.PrimaryScreen.Bounds.Width, Windows.Forms.Screen.PrimaryScreen.Bounds.Height)
        Dim ObjGraphics As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(ObjBitmap)

        ObjGraphics.CopyFromScreen(New Point(0, 0), New Point(0, 0), ScreenSize)
        ObjBitmap.Save("../images/test.bmp")
        ObjBitmap.Save("../images/ScreenCaptures/test.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
        '-- Cleen Up
        ObjGraphics.Dispose()
        ObjBitmap.Dispose()
    End Sub


End Class
