Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

259
Views
Take a screenshot of part of screen in c#

I want to take a screenshot of a specific part of a website using C# or .net Code, I can't create a Windows form application as it must be embedded into something else.

Here is what I got so far:

using System.Drawing.Imaging;
using System.Drawing;
using System;
using System.Windows.Forms;

try

  {
     //Creating a new Bitmap object

      Bitmap captureBitmap = new Bitmap(1024, 768, PixelFormat.Format32bppArgb);

     //Bitmap captureBitmap = new Bitmap(int width, int height, PixelFormat);
     //Creating a Rectangle object which will  
     //capture our Current Screen

     Rectangle captureRectangle = Screen.AllScreens[0].Bounds;

     //Creating a New Graphics Object

     Graphics captureGraphics = Graphics.FromImage(captureBitmap);

    //Copying Image from The Screen

captureGraphics.CopyFromScreen(captureRectangle.Left,captureRectangle.Top,0,0,captureRectangle.Size);

    //Saving the Image File (I am here Saving it in My E drive).

    captureBitmap.Save(@"E:\Capture.jpg",ImageFormat.Jpeg);

    //Displaying the Successfull Result

    MessageBox.Show("Screen Captured");

}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}

This code works fine as long as I am creating a windows form application, but as soon as I change it to console it doesn't work even after adding the "using System.Windows.Forms;" and it produces this error:

//Screen does not exist in the current context

So Is there any solution for this or any other way I could take a screenshot of a specific part of a website Programmatically without connecting to it at all.

Thanks in advance.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I actually found an answer one minute after posting from the suggested links "which btw didn't show in search I did for 2 days for some reason" but anyway

its This question

and its as simple as

Rectangle rect = new Rectangle(0, 0, 100, 100);
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(fileName, ImageFormat.Jpeg);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!