|
-
Dec 5th, 2008, 04:17 PM
#1
Thread Starter
Hyperactive Member
-
Dec 5th, 2008, 05:20 PM
#2
Re: [2005] Capture screen around mouse
you'll need to hook the wm_mousemove msg + (or maybe just) the WM_LBUTTONDBLCLK (?) msg, to catch a doubleclick + then capture a 32*32image from the screen using the coordinates in a wndProc. its not a simple job. try googling - hook WM_LBUTTONDBLCLK vb.net. theres some examples there but they're certainly not simple.
anyway, when you've hooked the msg, you catch it in a wndProc in your form + then grab your image from the screen.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 6th, 2008, 02:08 AM
#3
Re: [2005] Capture screen around mouse
Are you saying that you want this to be dynamic, kind of like a screen magnifier, or just an on-demand thing? If it's the latter then you can call the Graphics.CopyFromScreen method and use the Control.MousePosition property to determine the area to copy.
-
Dec 6th, 2008, 06:40 AM
#4
Thread Starter
Hyperactive Member
-
Dec 6th, 2008, 08:27 AM
#5
Re: [2005] Capture screen around mouse
 Originally Posted by knxrb
Also how would I use CopyFromScreen?
Much like the code example provided in the MSDN documentation for the CopyFromScreen method shows it, I would think.
If I tell someone what method to use to accomplish a task, it's my expectation that they will at least read the documentation for that method. It generally takes no more than 1 minute to open the MSDN documentation to the index, type in the the method name, click it in the list and then read the information provided. Are my expectations too high?
-
Dec 6th, 2008, 08:30 AM
#6
Thread Starter
Hyperactive Member
-
Dec 6th, 2008, 08:34 AM
#7
Re: [2005] Capture screen around mouse
 Originally Posted by knxrb
Well, that's the first step. Did you click on each of the overload signatures to read about each one? Each one is a link to the topic dedicated to that overload. That's how that interweb thingy works: read, click, read.
-
Dec 6th, 2008, 08:36 AM
#8
Thread Starter
Hyperactive Member
Re: [2005] Capture screen around mouse
[EDIT]
I've now got this, but all it gives me is a 1024x768 bitmap with a small 32x32 bitmap of where the mouse was...
Code:
Dim bmp As New Bitmap(1024, 768, Imaging.PixelFormat.Format32bppArgb)
Dim instance As Graphics = Graphics.FromImage(bmp)
Dim upperLeftSource As Point = New Point(PointToScreen(New Point(e.X - 16, e.Y - 16)).X, PointToScreen(New Point(e.X - 16, e.Y - 16)).Y)
Dim upperLeftDestination As Point = New Point(PointToScreen(New Point(e.X + 16, e.Y + 16)).X, PointToScreen(New Point(e.X + 16, e.Y + 16)).Y)
Dim blockRegionSize As Size = New Size(32, 32)
instance.CopyFromScreen(upperLeftSource, upperLeftDestination, blockRegionSize)
Mouse.picZoom.Image = bmp
bmp.Save("1.bmp")
[EDIT]
Yep, I've now got this...
Code:
Dim instance As Graphics
Dim upperLeftSource As Point = New Point(PointToScreen(New Point(e.X - 16, e.Y - 16)).X, PointToScreen(New Point(e.X - 16, e.Y - 16)).Y)
Dim upperLeftDestination As Point = New Point(PointToScreen(New Point(e.X + 16, e.Y + 16)).X, PointToScreen(New Point(e.X + 16, e.Y + 16)).Y)
Dim blockRegionSize As Size = New Size(32, 32)
instance.CopyFromScreen(upperLeftSource, upperLeftDestination, blockRegionSize)
...but how do I get that into a 32x32 bitmap image?
Last edited by knxrb; Dec 6th, 2008 at 08:45 AM.
Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

-
Dec 6th, 2008, 08:50 AM
#9
Re: [2005] Capture screen around mouse
Are you saying that you don't know why your Bitmap is 1024 x 768?
Code:
Dim bmp As New Bitmap(1024, 768, Imaging.PixelFormat.Format32bppArgb)
That's your code.
-
Dec 6th, 2008, 08:55 AM
#10
Re: [2005] Capture screen around mouse
I created a new project. I added a Button and a PictureBox. I added this code:
Code:
Private Sub Button1_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles Button1.Click
Dim bmp As New Bitmap(32, 32)
Dim sourceLocation As Point = Control.MousePosition
sourceLocation.Offset(-16, -16)
Using g As Graphics = Graphics.FromImage(bmp)
g.CopyFromScreen(sourceLocation, Point.Empty, bmp.Size)
End Using
Me.PictureBox1.Image = bmp
End Sub
I ran the project and clicked the Button.
-
Dec 6th, 2008, 09:01 AM
#11
Thread Starter
Hyperactive Member
-
Dec 6th, 2008, 09:18 AM
#12
Re: [2005] Capture screen around mouse
 Originally Posted by knxrb
No, I know why it's 1024x768, I want to know how I get the 32x32 bitmap that's displayed to be a 32x32 bitmap instead of it being a 1024x768 bitmap with a 32x32 bitmap where the cursor was.
That doesn't make sense. If you know why it's a 1024 x 768 Bitmap then you how to change the code to make it a 32 x 32 Bitmap. YOU are specifying the size of the Bitmap when you invoke the constructor. If you specify 1024 and 768 as the dimensions then of course it will be 1024 x 768. If you want it to be 32 x 32 then logic would dictate that those should be the dimensions you specify when you create it.
There also seems to be some confusion here as to what's a Bitmap and what isn't. There is no 1024 x 768 Bitmap with a 32 x 32 Bitmap inside it. There is only one Bitmap object and that's the one you create by invoking the Bitmap class constructor. That Bitmap will be whatever size you tell the constructor to make it. When you call CopyFromScreen you are NOT creating another Bitmap. You are simply copying some pixels from the screen onto the Bitmap you created. You specify the upper left corner of the area on screen, the upper left corner of the area on the canvas and the size of the area. The corner of the source area is 16 to the left and 16 above the cursor position:
Code:
sourceLocation.Offset(-16, -16)
The upper left corner of the target area is the upper left corner of the canvas itself, i.e. (0, 0):
Code:
g.CopyFromScreen(sourceLocation, Point.Empty, bmp.Size)
The size of the area is the size of the canvas:
Code:
g.CopyFromScreen(sourceLocation, Point.Empty, bmp.Size)
-
Dec 6th, 2008, 09:22 AM
#13
Thread Starter
Hyperactive Member
-
Dec 6th, 2008, 09:29 AM
#14
Re: [2005] Capture screen around mouse
I don't understand what you're trying to say. I've already shown you how to create a 32x32 Bitmap and copy a 32x32 area of the screen centred on the mouse cursor to that Bitmap. Are you saying that that isn't what you want? If so then you're going to have to try again to explain what you DO want because I have no idea. If what I've described IS what you want then I don't understand what the problem is.
-
Dec 6th, 2008, 09:31 AM
#15
Thread Starter
Hyperactive Member
-
Dec 6th, 2008, 09:35 AM
#16
Re: [2005] Capture screen around mouse
 Originally Posted by knxrb
somehow I missed post #10
What? You missed my best work in this thread? Alls is well what endses well.
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
|