Results 1 to 8 of 8
  1. #1
    ³²³'s Avatar
    Join Date
    Mar 2011
    Gender
    male
    Location
    sef
    Posts
    302
    Reputation
    9
    Thanks
    19
    My Mood
    Angelic

    [Tutorial] Bitmap images: the correct way

    Today I will show you how to correctly dispose of an image, freeing it from your program and "unlocking" it to be deleted/renamed/edited/copied.

    Add this above "Public Class formname"
    Code:
    Imports System
    Imports System.IO
    Imports System. Runtime.InteropServices
    Imports System.Drawing
    Imports System.Drawing.Imaging
    Add this into a class
    Code:
    Imports System
    Imports System. Runtime.InteropServices
    Imports System.Drawing
    Imports System.Drawing.Imaging
    
    
    Namespace ScreenShot
        Public Class ScreenCapture
    
            Public Function CaptureScreen() As Image ' Capture The Screen!
    'This next will return an image 
    'using your desktop screen capture
                Return CaptureIt(User32.GetDesktopWindow())
            End Function
    
            Public Function CaptureIt(ByVal handle As IntPtr) As Image
                Dim SRCCOPY As Integer = &HCC0020
                Dim hdcSrc As IntPtr = User32.GetWindowDC(handle)
                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
                Dim hdcDest As IntPtr = GDI32.CreateCompatibleDC(hdcSrc)
                Dim hBitmap As IntPtr = GDI32.CreateCompatibleBitmap(hdcSrc, width, height)
                Dim hOld As IntPtr = GDI32.SelectObject(hdcDest, hBitmap)
                GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, SRCCOPY)
                GDI32.SelectObject(hdcDest, hOld)
                GDI32.DeleteDC(hdcDest)
                User32.ReleaseDC(handle, hdcSrc)
                Dim img As Image = Image.FromHbitmap(hBitmap)
                GDI32.DeleteObject(hBitmap)
                Return img
            End Function
    
            Public Sub CaptureScreenToFile(ByVal pathPNG As String)
                Dim image As Image = CaptureScreen()
                Dim imagecopy As New Bitmap(image)
                image.Dispose()
                imagecopy.Save(pathPNG, Imaging.ImageFormat.Png)
            End Sub
    
            Private Class GDI32
                Public SRCCOPY As Integer = &HCC0020
                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
    
            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
    
                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
        End Class
    End Namespace
    Then just use this as your image capturing. It will capture the entire screen and save to "C:\image.png".
    Code:
    Dim SCRCapture as new ScreenCapture
    SCRCapture.CaptureScreenToFile("C:\image.png")
    Then, if you want to delete the file later:
    Code:
    File.Delete("C:\image.png")
    If you wanted to delete the file but used
    Code:
    Dim originalimage As Bitmap = CaptureScreen()
    originalimage.Save("C:\image.png", Imaging.ImageFormat.Png)
    it would throw an exception eventually whether after one click or two clicks of the "Delete" button (or whatever sub you have the File.Delete under).

    Press thanks if this helped you at all.

    @³²³

    Credits for GDI32:
    https://www.codeprojec*****m/KB/GDI-plus/BitBlt.aspx

    Credits for original C# code that I cleaned up:
    https://www.developerfusion.co.uk/show/4630/
    Last edited by ³²³; 03-30-2011 at 01:29 PM.

    Quote Originally Posted by $0WhaT ?
    Hey sherlock u cant put a keygen on a .php
    Quote Originally Posted by ³²³
    Keygen.php is not a valid vBulletin file. It's there for cracking purposes
    Quote Originally Posted by $0WhaT ?
    Maybe but idc it doesn mean i am a keylogger

  2. #2
    Lyoto Machida's Avatar
    Join Date
    Jan 2011
    Gender
    male
    Location
    Far away with girls
    Posts
    3,734
    Reputation
    133
    Thanks
    1,621
    My Mood
    Aggressive
    Good Job ^^

  3. #3
    ³²³'s Avatar
    Join Date
    Mar 2011
    Gender
    male
    Location
    sef
    Posts
    302
    Reputation
    9
    Thanks
    19
    My Mood
    Angelic
    Press thanks Glad you like it.

    Quote Originally Posted by $0WhaT ?
    Hey sherlock u cant put a keygen on a .php
    Quote Originally Posted by ³²³
    Keygen.php is not a valid vBulletin file. It's there for cracking purposes
    Quote Originally Posted by $0WhaT ?
    Maybe but idc it doesn mean i am a keylogger

  4. #4
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    C+P fag. No explanation ?

  5. The Following User Says Thank You to Hassan For This Useful Post:

    [MPGH]master131 (03-29-2011)

  6. #5
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Gotta include credits. Obv leech is obv.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  7. #6
    ³²³'s Avatar
    Join Date
    Mar 2011
    Gender
    male
    Location
    sef
    Posts
    302
    Reputation
    9
    Thanks
    19
    My Mood
    Angelic
    I used a gdi32 and user32 class I found somewhere and a screencapture class I also found somewhere. Reason I can't include credits is because I have no idea where those somewheres are :/

  8. #7
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    So at least say that you got the functions from somewhere I guess, otherwise people will assume you're deliberately not giving credits.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  9. #8
    ³²³'s Avatar
    Join Date
    Mar 2011
    Gender
    male
    Location
    sef
    Posts
    302
    Reputation
    9
    Thanks
    19
    My Mood
    Angelic
    Added Credits, also the vb.net version here was buggy. So I fixed some errors.

    Quote Originally Posted by $0WhaT ?
    Hey sherlock u cant put a keygen on a .php
    Quote Originally Posted by ³²³
    Keygen.php is not a valid vBulletin file. It's there for cracking purposes
    Quote Originally Posted by $0WhaT ?
    Maybe but idc it doesn mean i am a keylogger