1 Attachment(s)
[2005] Capture screen around mouse
How do I capture a screenshot of the current screen around the mouse?
The idea is that I get a little 32x32 image of the area around screen at the mouse location so that the mouse point is in the center?
Please see attached picture for another example.
Thanks in advance, knxrb :D
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.
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.
Re: [2005] Capture screen around mouse
It's supposed to be a magnifier that gets you a closer look at the area around the mouse.
It would only call it when the mosue moves around my picturebox.
Also how would I use CopyFromScreen?
Re: [2005] Capture screen around mouse
Quote:
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?
Re: [2005] Capture screen around mouse
Re: [2005] Capture screen around mouse
Quote:
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.
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?
Re: [2005] Capture screen around mouse
Are you saying that you don't know why your Bitmap is 1024 x 768?
Quote:
Code:
Dim bmp As New Bitmap(1024, 768, Imaging.PixelFormat.Format32bppArgb)
That's your code.
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.
Re: [2005] Capture screen around mouse
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.
Re: [2005] Capture screen around mouse
Quote:
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:
Quote:
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):
Quote:
Code:
g.CopyFromScreen(sourceLocation, Point.Empty, bmp.Size)
The size of the area is the size of the canvas:
Quote:
Code:
g.CopyFromScreen(sourceLocation, Point.Empty, bmp.Size)
1 Attachment(s)
Re: [2005] Capture screen around mouse
This is what i mean when I have a 1024x768 bitmap with a 32x32 picture at the mouse location:
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.
Re: [2005] Capture screen around mouse
Re: [2005] Capture screen around mouse
Quote:
Originally Posted by knxrb
somehow I missed post #10
What? You missed my best work in this thread? :) Alls is well what endses well.