Results 1 to 3 of 3
  1. #1
    ThreadOP's Avatar
    Join Date
    Jul 2014
    Gender
    female
    Posts
    23
    Reputation
    10
    Thanks
    91

    VB2010 .GIF Recorder (.NET 4.0)

    First you'll need this screenshot class

    Copy and past this into a class file.
    Code:
    Imports System
    Imports System.Runtime.InteropServices
    Imports System.Drawing
    Imports System.Drawing.Imaging
    Namespace ScreenShot
        '/ Provides functions to capture the entire screen, or a particular window, and save it to a file.
        Public Class ScreenCapture
            '/ Creates an Image object containing a screen shot of the entire desktop
            Public Function CaptureScreen() As Image
                Return CaptureWindow(User32.GetDesktopWindow())
            End Function 'CaptureScreen
            '/ Creates an Image object containing a screen shot of a specific window
            Public Function CaptureWindow(ByVal handle As IntPtr) As Image
                Dim SRCCOPY As Integer = &HCC0020
                ' get te hDC of the target window
                Dim hdcSrc As IntPtr = User32.GetWindowDC(handle)
                ' get the size
                Dim windowRect As New User32.RECT
                User32.GetWindowRect(handle, windowRect)
                Dim width As Integer = windowRect.right - windowRect.left
                Dim height As Integer = windowRect.bottom - windowRect.top
                ' create a device context we can copy to
                Dim hdcDest As IntPtr = GDI32.CreateCompatibleDC(hdcSrc)
                ' create a bitmap we can copy it to,
                ' using GetDeviceCaps to get the width/height
                Dim hBitmap As IntPtr = GDI32.CreateCompatibleBitmap(hdcSrc, width, height)
                ' select the bitmap object
                Dim hOld As IntPtr = GDI32.SelectObject(hdcDest, hBitmap)
                ' bitblt over
                GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, SRCCOPY)
                ' restore selection
                GDI32.SelectObject(hdcDest, hOld)
                ' clean up 
                GDI32.DeleteDC(hdcDest)
                User32.ReleaseDC(handle, hdcSrc)
    
                ' get a .NET image object for it
                Dim img As Image = Image.FromHbitmap(hBitmap)
                ' free up the Bitmap object
                GDI32.DeleteObject(hBitmap)
    
                Return img
            End Function 'CaptureWindow
            '/ Captures a screen shot of a specific window, and saves it to a file
            Public Sub CaptureWindowToFile(ByVal handle As IntPtr, ByVal filename As String, ByVal format As ImageFormat)
                Dim img As Image = CaptureWindow(handle)
                img.Save(filename, format)
            End Sub 'CaptureWindowToFile
            '/ Captures a screen shot of the entire desktop, and saves it to a file
            Public Sub CaptureScreenToFile(ByVal filename As String, ByVal format As ImageFormat)
                Dim img As Image = CaptureScreen()
                img.Save(filename, format)
            End Sub 'CaptureScreenToFile
            Public Function CaptureDeskTopRectangle(ByVal CapRect As Rectangle, ByVal CapRectWidth As Integer, ByVal CapRectHeight As Integer) As Bitmap
                '/ Returns BitMap of the region of the desktop, similar to CaptureWindow, but can be used to 
                '/ create a snapshot of the desktop when no handle is present, by passing in a rectangle 
                '/ Grabs snapshot of entire desktop, then crops it using the passed in rectangle's coordinates
                Dim SC As New ScreenShot.ScreenCapture
                Dim bmpImage As New Bitmap(sc.CaptureScreen)
                Dim bmpCrop As New Bitmap(CapRectWidth, CapRectHeight, bmpImage.PixelFormat)
                Dim recCrop As New Rectangle(CapRect.X, CapRect.Y, CapRectWidth, CapRectHeight)
                Dim gphCrop As Graphics = Graphics.FromImage(bmpCrop)
                Dim recDest As New Rectangle(0, 0, CapRectWidth, CapRectHeight)
                gphCrop.DrawImage(bmpImage, recDest, recCrop.X, recCrop.Y, recCrop.Width, _
                  recCrop.Height, GraphicsUnit.Pixel)
                Return bmpCrop
            End Function
            '/ Helper class containing Gdi32 API functions
            Private Class GDI32
                Public SRCCOPY As Integer = &HCC0020
                ' BitBlt dwRop parameter
                Declare Function BitBlt Lib "gdi32.dll" ( _
                    ByVal hDestDC As IntPtr, _
                    ByVal x As Int32, _
                    ByVal y As Int32, _
                    ByVal nWidth As Int32, _
                    ByVal nHeight As Int32, _
                    ByVal hSrcDC As IntPtr, _
                    ByVal xSrc As Int32, _
                    ByVal ySrc As Int32, _
                    ByVal dwRop As Int32) As Int32
    
                Declare Function CreateCompatibleBitmap Lib "gdi32.dll" ( _
                    ByVal hdc As IntPtr, _
                    ByVal nWidth As Int32, _
                    ByVal nHeight As Int32) As IntPtr
    
                Declare Function CreateCompatibleDC Lib "gdi32.dll" ( _
                    ByVal hdc As IntPtr) As IntPtr
    
                Declare Function DeleteDC Lib "gdi32.dll" ( _
                    ByVal hdc As IntPtr) As Int32
    
                Declare Function DeleteObject Lib "gdi32.dll" ( _
                    ByVal hObject As IntPtr) As Int32
    
                Declare Function SelectObject Lib "gdi32.dll" ( _
                    ByVal hdc As IntPtr, _
                    ByVal hObject As IntPtr) As IntPtr
            End Class 'GDI32
            '/ Helper class containing User32 API functions
            Public Class User32
                <StructLayout(LayoutKind.Sequential)> _
                Public Structure RECT
                    Public left As Integer
                    Public top As Integer
                    Public right As Integer
                    Public bottom As Integer
                End Structure 'RECT
    
                Declare Function GetDesktopWindow Lib "user32.dll" () As IntPtr
    
                Declare Function GetWindowDC Lib "user32.dll" ( _
                    ByVal hwnd As IntPtr) As IntPtr
    
                Declare Function ReleaseDC Lib "user32.dll" ( _
                    ByVal hwnd As IntPtr, _
                    ByVal hdc As IntPtr) As Int32
    
                Declare Function GetWindowRect Lib "user32.dll" ( _
                    ByVal hwnd As IntPtr, _
                    ByRef lpRect As RECT) As Int32
    
            End Class 'User32
        End Class 'ScreenCapture 
    End Namespace 'ScreenShot
    To save and 'compile' your image files into an animating .GIF file.
    Code:
    Public Sub createGif(ByVal Filename As String)
            Try
                Dim Encoder As New System.Windows.Media.Imaging.GifBitmapEncoder
                Dim imageList As New List(Of IO.FileStream)
                For Each imageFile As String In My.Computer.FileSystem.GetFiles(SavePath, FileIO.SearchOption.SearchTopLevelOnly, "*.jpeg")
                    Dim fileStream1 As New IO.FileStream(imageFile, IO.FileMode.Open)
                    Dim createFrames = System.Windows.Media.Imaging.BitmapFrame.Create(fileStream1)
                    imageList.Add(fileStream1)
                    Encoder.Frames.Add(createFrames)
                Next
                Dim fileStream2 As New IO.FileStream(Filename, IO.FileMode.OpenOrCreate)
                Encoder.Save(fileStream2)
                fileStream2.Close()
    
                For Each f As IO.FileStream In imageList
                    f.Close()
                Next
    
            Catch ex As Exception
    
            End Try
    
            Try : System****.Directory.Delete(SavePath, True) : Catch : End Try
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImageInterval.Tick
            Dim sc As New ScreenShot.ScreenCapture
            Dim b As Bitmap = sc.CaptureDeskTopRectangle(New Rectangle(New Point(LocationX, LocationY), New Size(SizeX, SizeY)), SizeX, SizeY)
            b.Save(SavePath & "\" & Count.ToString & ".jpeg")
            Count += 1
        End Sub
    Screen Region Drag Selection (I just use a new form for this)
    Code:
    Imports System.MathHoffa 'what a dizaster!
    
    Public Class dragRegion
    
    
        Private MyRectangle As Rectangle
        Private Drawing As Boolean = False
        Private StartX, StartY, CursorX, CursorY As Single
    
    
        Private Sub Region_Drag_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
            If Drawing = True Then
                Dim Oral_Pen As New Pen(Brushes.Yellow, 4)
                Oral_Pen.DashStyle = Drawing2D.DashStyle.DashDot
                MyRectangle = New Rectangle(Min(StartX, CursorX), _
                                          Min(StartY, CursorY), _
                                          Abs(StartX - CursorX), _
                                          Abs(StartY - CursorY))
    
                e.Graphics.FillRectangle(New SolidBrush(Color.Fuchsia), MyRectangle)
                e.Graphics.DrawRectangle(Oral_Pen, MyRectangle)
            End If
        End Sub
    
        Private Sub Region_Drag_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
            If e.KeyCode = Keys.Escape Then
                Me.Close()
            End If
        End Sub
    
        Private Sub Region_Drag_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
            Drawing = True
            StartX = e.X
            StartY = e.Y
            CursorX = e.X
            CursorY = e.Y
        End Sub
    
        Private Sub Region_Drag_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
            If Not Drawing Then Exit Sub
            Dim G As Graphics = Me.CreateGraphics
            CursorX = e.X
            CursorY = e.Y
            Me.Invalidate()
        End Sub
    
    
        Private Sub Region_Drag_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
            Drawing = False
            Dim G As Graphics = Me.CreateGraphics
            G.DrawRectangle(Pens.Black, MyRectangle.X, MyRectangle.Y, MyRectangle.Width, MyRectangle.Height)
            Me.Invalidate()
    
            Me.Dispose()
        End Sub
    
    
        Private Sub Region_Drag_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim sc As New ScreenShot.ScreenCapture
            Me.Focus()
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
            Me.TopMost = True
            Me.Location = New Point(0, 0)
            Me.Size = Screen.PrimaryScreen.Bounds.Size
    
            Me.DoubleBuffered = True
    
        End Sub
    End Class

    Starting / Stopping Recording
    Code:
        Public Sub StartRec()
            Try
                Count = 1
                If Not IO.Directory.Exists(SavePath) Then
                    IO.Directory.CreateDirectory(SavePath)
                End If
            Catch : End Try
                Try : ImageInterval.Start() : Catch ex As Exception
                  
                End Try
        End Sub
    
        Public Sub StopRec()
            Try : ImageInterval.Stop() : Catch : Exit Sub : End Try
            Me.Show()
            sfd.FileName = ""
            sfd.Filter = "Gif File (*.gif)|*.gif"
            If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
                createGif(sfd.FileName)
            End If
        End Sub
    I would post the source or the .exe file(again) but this section has no minions so I'm not going to even bother. >_>
    Last edited by ThreadOP; 08-23-2014 at 09:38 AM.

  2. The Following User Says Thank You to ThreadOP For This Useful Post:

    EliteTaco9000 (08-23-2014)

  3. #2
    EliteTaco9000's Avatar
    Join Date
    Aug 2014
    Gender
    male
    Posts
    0
    Reputation
    21
    Thanks
    752
    My Mood
    Busy
    Really HQ post! what kind of quality does this make? i usually record a video and edit it in photoshop, so quality loss isnt really a problem.

  4. #3
    ThreadOP's Avatar
    Join Date
    Jul 2014
    Gender
    female
    Posts
    23
    Reputation
    10
    Thanks
    91
    Quote Originally Posted by EliteTaco9000 View Post
    Really HQ post! what kind of quality does this make? i usually record a video and edit it in photoshop, so quality loss isnt really a problem.
    I don't have to handle the quality or compression of images because I'm retarded and don't know how to program. If you want to lower your file size and or handle the quality. You'll probably want to do it with the image files not the actual gif output. But I don't know

Similar Threads

  1. [Release] .Gif Recorder (Easily create .GIF animations)
    By ThreadOP in forum Programming Tools
    Replies: 5
    Last Post: 08-23-2014, 11:51 AM
  2. [VB.Net] Record Screen
    By jabbathehutt in forum Visual Basic Programming
    Replies: 13
    Last Post: 11-04-2010, 03:49 PM
  3. recording packet help!!!!!
    By iwillkillyou in forum WarRock - International Hacks
    Replies: 5
    Last Post: 01-27-2006, 07:48 AM
  4. Gangsterhood.net
    By supatanka in forum Hack Requests
    Replies: 0
    Last Post: 01-22-2006, 01:42 PM