Results 1 to 16 of 16

Thread: Custom Screen Shot ?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2009
    Posts
    462

    Custom Screen Shot ?

    is there anyway i can do a a custom screen shot ? like
    the height and width of it ?
    this is what i want to do
    Left= 18
    top = 556
    right = 914
    bottom = 289

    so a regular screen shot on my pc is 1152 by 864
    so how would i say do a 300 by 400 screen shot ?

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Custom Screen Shot ?

    Your existing code can do it - you just need to pass in those parameters.

    Take a look at the MSDN documentation on CopyFromScreen
    Last edited by keystone_paul; Jul 2nd, 2009 at 07:59 AM.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2009
    Posts
    462

    Re: Custom Screen Shot ?

    hmm.. why isnt this working ?
    Code:
    Public Class Form1
        Public Sub CopyFromScreen( _
        ByVal upperLeftSource As Point, _
        ByVal upperLeftDestination As Point, _
        ByVal blockRegionSize As Size _
    )
        End Sub
        Dim instance As Graphics
        Dim upperLeftSource As Point
        Dim upperLeftDestination As Point
        Dim blockRegionSize As Size
    
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            instance.CopyFromScreen(upperLeftSource, _
        upperLeftDestination, blockRegionSize)
    
            e.Graphics.CopyFromScreen(Me.Location, _
           New Point(40, 40), New Size(100, 100))
    
    
        End Sub
    
    End Class

  4. #4
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Custom Screen Shot ?

    Well in that example you have declared but not initialised "instance", "upperLeftSource" etc, unless you have set them up in code that you aren't showng.

    Are you getting an error message or is it just not copying anything?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2009
    Posts
    462

    Re: Custom Screen Shot ?


  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Custom Screen Shot ?

    A button clicks event args doesn't have a graphics object.

    You would have to create a graphics object instance. If you are looking to make a screenshot and save it, I would make an image the size of the desired screenshot, and create graphics from that (ie graphics.fromimage)

  7. #7
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Custom Screen Shot ?

    Thats because e is of type System.EventArgs, which doesn't have a property called graphics.

    If it was in the button paint event it would as e is of type System.Windows.Forms.PaintEventArgs which does provide one.

    If you want a graphics object to draw on you'll either need to get it from an object that provides one, or create a new one.

    EDIT - Kleinma beat me to it!

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2009
    Posts
    462

    Re: Custom Screen Shot ?

    got a link to one ? that has already been made ? i couldn't find one on the search

  9. #9
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Custom Screen Shot ?

    Here is a sample you can use and modify to your needs.

    Code:
            'SPECIFY TO GET SCREENSHOT AT LOCATION 100x100 (x/y coord), WITH A SIZE OF 200x200
            Dim myScreenshotBounds As New Rectangle(100, 100, 200, 200)
    
            'CREATE A BITMAP WITH THE DESIRED SIZE OF OUR SCREENSHOT
            Dim myBitmap = New Bitmap(myScreenshotBounds.Width, myScreenshotBounds.Height, Imaging.PixelFormat.Format32bppArgb)
    
            'CREATE GRAPHICS OBJECT FROM BITMAP
            Dim myGraphics = Graphics.FromImage(myBitmap)
    
            'COPY SCREEN IMAGE BASED ON LOCATION AND SIZE WE WANT
            myGraphics.CopyFromScreen(myScreenshotBounds.Location, New Point(0, 0), myScreenshotBounds.Size)
    
            'SAVE BITMAP TO FILE
            myBitmap.Save("C:\test.bmp")
    
            'DISPOSE OF OBJECTS
            myBitmap.Dispose()
            myGraphics.Dispose()

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2009
    Posts
    462

    Re: Custom Screen Shot ?

    okay will i dont want to save it so i edited it and im getting a ERROR


    i just want to replace this code's screen capture with yours but it doesn't seem to be working when i changed it ?
    this is my Code for moving the mouse to a pixel and i need Your code to work so it doesnt Lag as much when i set the command to move the cursor

    PHP Code:
    Public Class PixelSearch
        
    Function ScreenshotForm() As Bitmap
            Dim bounds 
    As Rectangle
            Dim BMP 
    As System.Drawing.Bitmap
            Dim graph 
    As Graphics
            bounds 
    Screen.PrimaryScreen.Bounds
            BMP 
    = New System.Drawing.Bitmap(bounds.Widthbounds.HeightSystem.Drawing.Imaging.PixelFormat.Format32bppArgb)
            
    graph Graphics.FromImage(BMP)
            
    graph.CopyFromScreen(bounds.Xbounds.Y00bounds.SizeCopyPixelOperation.SourceCopy)
            Return 
    BMP
        End 
    Function
        Public Declare 
    Auto Function SetCursorPos Lib "User32.dll" (ByVal X As IntegerByVal Y As Integer) As Integer
        
    Public Declare Auto Function GetCursorPos Lib "User32.dll" (ByRef lpPoint As Point) As Integer
         End Sub
        
    Private Sub MoveMousetoPixel(ByVal Clr As Color)
            
    Dim BMP As Bitmap ScreenshotForm()

            For 
    As Integer 1 To BMP.Width 1
                
    For As Integer 1 To BMP.Height 1
                    
    If BMP.GetPixel(xy).ToArgb Clr.ToArgb Then
                        Cursor
    .Position = New Point(xy)
                        Exit 
    Sub
                    End 
    If
                
    Next
            Next
        End Sub
        
    Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles Button1.Click
            rgb
    .Show()
            
    Me.Hide()
        
    End Sub

        
    Private Sub Button2_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles ToolStripLabel1.Click
            MoveMousetoPixel
    (Color.FromArgb(255TextBox1.TextTextBox2.TextTextBox3.Text))

        
    End Sub

        End Sub
    End 
    Class 

  11. #11
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Custom Screen Shot ?

    Don't call dispose() on myBitmap if you are assigning it to a picturebox because images are reference types (they only exist in 1 spot in memory) so assigning a bitmap to a picturebox's backgroundimage property, and then after that you dispose of the image basically clearing it from memory.

    So just take out the myBitmap.Dispose() line, and I think you wouldn't get that error anymore.

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2009
    Posts
    462

    Re: Custom Screen Shot ?

    okay ty it works but is there something in the codebank that can show me the SCREENSHOT LOCATION
    so i can get the size Right when i take me screen shot ?

    ty so much for your Help
    keystone_paul
    &
    kleinma
    you guys always help me even tho i don't understand most of it

  13. #13
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Custom Screen Shot ?

    I don't know what you mean because I don't know how you want to determine what size and location to take your screenshot at. Are you looking to do something like drag the mouse to make a rectangle and screenshot that? or are you looking to enter specific coordinates and take the screenshot based on that? or something else?

    As far as the codebank goes, I have no idea what is in it other than things I have submitted myself. I suggest using the form search feature if you want to try to find if something exists in the codebank.

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2009
    Posts
    462

    Re: Custom Screen Shot ?

    okay sorry i didn't really say it that well okay this is a regular screen shot



    now say the Black bricks are where i have moved my Mouse every time i move my mouse to a spot i will press a HotKey to save the Location of it so every Back spot is where i have moved my mouse and saved that location



    now after i click the screen shot button i would want it to look like this


    [IMG][/IMG]

    now do you understand what i want to do ?

  15. #15
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Custom Screen Shot ?

    I guess a few questions:

    1) Are you looking to actually display these "black squares" or some sort of visual indicator on the screen during this process?

    2) I don't see the point in 4 blocks. You are only taking a rectangular screenshot. Specifying an upper left coordinate, and a bottom right coordinate is all you need, the other 2 coordinates are implied by the first 2.

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2009
    Posts
    462

    Re: Custom Screen Shot ?

    okay well i think this would be a better way of doing this

    but when Click the Save Location
    how can i get the form1.Location then send it to 2 text box's ?

    Code:
      Dim myScreenshotBounds As New Rectangle(TextBox4.Text, TextBox4.Text, TextBox5.Text, TextBox5.Text)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width