I have a c# form that I setup with
int INTERFACE_right = 20;
int INTERFACE_down = 25;
int INTERFACE_width = 846;
int INTERFACE_height = 60;
this.Left = INTERFACE_right;
this.Top = INTERFACE_down;
this.Size = new Size(INTERFACE_width, INTERFACE_height);
And I copy a part of the screen with (I hide the form before with the opacity) with the exact same parameter. So the form should be exactly on top of the part of the screen I copy:
Bitmap grabOnScreen(){
Rectangle rect = new Rectangle(INTERFACE_right, INTERFACE_down, INTERFACE_width, INTERFACE_height);
Bitmap bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bmp);
g.CopyFromScreen(rect.Left, rect.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy);
//bmp.Save("test.jpg", ImageFormat.Jpeg);
return bmp;
}
As I save the image to test.jpg
, I know I grab the good part of the screen with the right dimensions etc.
The form should have the same size, and the same location than where I grab the picture, but in pratice the form is bigger than the picture, but as the good location.
How can I match the form size to the same than the rect where i grab the picture ?