Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda