Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Have this code for take screen shot from windows :
C#
Rectangle bounds = Screen.GetBounds(Screen.GetBounds(Point.Empty));
            Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height);
            Graphics g = Graphics.FromImage(bitmap);
            g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);

what does last line actually do ?
if i delete last line the bitmap is black , but the last line does not any work with bitmap !
thanks , Arman

What I have tried:

I've tried this :
TeboScreen: Basic C# Screen Capture Application[^]
Posted
Updated 12-Oct-17 23:06pm

You can check the documentation:
Graphics.CopyFromScreen Method[^]
There it is stated that it
Quote:
Performs a bit-block transfer of color data from the screen to the drawing surface of the Graphics.

Therefore, the last line actually does something with the bitmap, simply by interfering with its underlying Graphics object.
Kindly.
 
Share this answer
 
Comments
Member 10209926 13-Oct-17 5:04am    
Thanks I've got my answer .
phil.o 13-Oct-17 5:13am    
You're welcome :)
The line:
C#
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
Copies the current screen (or the primary screen if you have more than one) and draws it into teh bitmap: if you add
C#
bitmap.Save(@"D:\Temp\Screen.bmp");
You will be able to see the image clearly.

Point.Empty is just a shorthand for new Point(0, 0) so it copies from the top left of the screen to the top left of the output bitmap, and bounds.Size says to copy the entire screen.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900