Hello Everyone.
In this article: You will know to capture the screen in 2 ways:
1)- Capture full screen.
2)- Capture region.
Let's Begin:
First make a new Windows Application project.
And make sure your program uses these namespaces: -
using System;
-
using System.Drawing;
-
using System.Drawing.Imaging;
-
using System.Windows.Forms;
-
Now, we will begin writing the code:
1)- Create a new bitmap object. -
//Bitmap screenBitmap = new Bitmap(int width, int height, PixelFormat);
-
Bitmap screenBitmap = new Bitmap(1024, 768, PixelFormat.Format32bppArgb);
-
2)- Create a new rectangle object. -
//screenRegion will grab the size of your current screen.
-
Rectangle screenRegion = Screen.AllScreens[0].Bounds;
-
3)- Create a new graphics object. -
Graphics screenGraphics = Graphics.FromImage(screenBitmap);
-
4)- Copy the image from the screen. -
//screenGraphics will copy the image from the screen.
-
screenGraphics.CopyFromScreen(screenRegion.Left, screenRegion.Top, 0, 0, screenRegion.Size);
-
5)- Save the image: -
screenBitmap.Save(@"C:\Screen.jpg", ImageFormat.Jpeg);
-
Here is the code: -
Bitmap screenBitmap = new Bitmap(1024, 768, PixelFormat.Format32bppArgb);
-
Rectangle screenRegion = Screen.AllScreens[0].Bounds;
-
-
// It will copy the current screep image to the bitmap image.
-
Graphics screenGraphics = Graphics.FromImage(screenBitmap);
-
screenGraphics.CopyFromScreen(screenRegion.Left, screenRegion.Top, 0, 0, screenRegion.Size);
-
-
screenBitmap.Save(@"c:\test.jpg", ImageFormat.Jpeg);
-
You can also capture a part of the screen (region): -
/* The Code was:
-
screenGraphics.CopyFromScreen(screenRegion.Left, screenRegion.Top, 0, 0, screenRegion.Size);
-
*/
-
-
//See the difference.
-
-
//screenGraphics.CopyFromScreen(intSourceX, intSourceY......);
-
screenGraphics.CopyFromScreen(200, 300, 0, 0, screenRegion.Size);
-
Hope this help you.
5 8978
Hey Atran
Thanks!
Its nice stuff with good and simple explanation
Hey Atran
Thanks!
Its nice stuff with good and simple explanation
You're welcome, enjoy.......
Great tip
this is something that I can use daily with a few modifications.
I do not use C# though so I thought that you would not mind if I posted the VB code - Imports System
-
Imports System.drawing
-
Imports System.Drawing.Imaging
-
Imports System.Windows.Forms
-
Dim screenBitmap As New Bitmap(1024, 768, PixelFormat.Format32bppArgb)
-
Dim screenRegion As Rectangle = Screen.AllScreens(0).Bounds
-
-
' It will copy the current screep image to the bitmap image.
-
Dim screenGraphics As Graphics = Graphics.FromImage(screenBitmap)
-
screenGraphics.CopyFromScreen(screenRegion.Left, screenRegion.Top, 0, 0, screenRegion.Size)
-
-
screenBitmap.Save("c:\test.jpg", ImageFormat.Jpeg)
this was really good one!!
Thanx
Hi ,
The above code is working gr8 in development machine.Once i deploy it in the server its giving 'Handle Invalid' error.
Any suggestion
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Adrian Lumsden |
last post by:
Hello,
I have an app where I have to screen scrape to capture an image from a JMF
film player.
The user is given a dialog with a list of frames that can be exported as
images. If the one they...
|
by: Me Mine |
last post by:
i,
I have trying to code a small console app that will
allow a user to select a window and then create a
screen capture of the window. I haven't been able to
figure out how to do the screen...
|
by: xc |
last post by:
Greetings.
I encountered a wield problem when grabing screen images.
Sometimes in some computers I can capture the screen, but other times not
so.
In some computer I cannot capture the screen...
|
by: Rattanak Song |
last post by:
Hi,
I'm trying to build a database which can capture a still image from a
digital camera or web cam and import to the database via an Object or
something like that.
Any help would be very...
|
by: hellokitty |
last post by:
GetDC/GetWindowDC can only capture on screen,visually, stuff and not
for screen in background
If I execute an exe in other desktop, by CreateDesktop/SwitchDesktop, it
requires to actually...
|
by: Pohihihi |
last post by:
Hello NG,
How can I take a snapshot of full screen (of a area of screen as needed)
using any dotNet language?
Thank you,
Po
|
by: Clif |
last post by:
Hi,
I would like to find out exactly what is being sent when a web page uses the
post request method. My thought was to use the webbrowser control together
with the HTTPWebRequest class, but am...
|
by: Tuy Solang |
last post by:
Hi Everyone,
I am just starting to learn Java from O'Reilly CD. I could not find
any example that is related to screen capture. Is it possible in Java
like in Microsoft C?
Thanks,
|
by: raylopez99 |
last post by:
Beware newbies: I spent a day before I figured this out: copying a
bitmap (image) file to file is not quite like copying a text file--you
have to do some tricks (see below), like using a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |