|
-
Jul 2nd, 2009, 07:46 AM
#1
Thread Starter
Hyperactive Member
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 ?
-
Jul 2nd, 2009, 07:50 AM
#2
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.
-
Jul 2nd, 2009, 08:53 AM
#3
Thread Starter
Hyperactive Member
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
-
Jul 2nd, 2009, 09:08 AM
#4
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?
-
Jul 2nd, 2009, 09:18 AM
#5
Thread Starter
Hyperactive Member
-
Jul 2nd, 2009, 09:21 AM
#6
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)
-
Jul 2nd, 2009, 09:23 AM
#7
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!
-
Jul 2nd, 2009, 11:00 AM
#8
Thread Starter
Hyperactive Member
Re: Custom Screen Shot ?
got a link to one ? that has already been made ? i couldn't find one on the search
-
Jul 2nd, 2009, 11:12 AM
#9
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()
-
Jul 2nd, 2009, 11:48 AM
#10
Thread Starter
Hyperactive Member
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.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(BMP)
graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
Return BMP
End Function
Public Declare Auto Function SetCursorPos Lib "User32.dll" (ByVal X As Integer, ByVal 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 x As Integer = 1 To BMP.Width - 1
For y As Integer = 1 To BMP.Height - 1
If BMP.GetPixel(x, y).ToArgb = Clr.ToArgb Then
Cursor.Position = New Point(x, y)
Exit Sub
End If
Next
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
rgb.Show()
Me.Hide()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripLabel1.Click
MoveMousetoPixel(Color.FromArgb(255, TextBox1.Text, TextBox2.Text, TextBox3.Text))
End Sub
End Sub
End Class
-
Jul 2nd, 2009, 12:31 PM
#11
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.
-
Jul 2nd, 2009, 01:40 PM
#12
Thread Starter
Hyperactive Member
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
-
Jul 2nd, 2009, 01:43 PM
#13
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.
-
Jul 2nd, 2009, 02:08 PM
#14
Thread Starter
Hyperactive Member
-
Jul 2nd, 2009, 02:24 PM
#15
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.
-
Jul 2nd, 2009, 03:23 PM
#16
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|