Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

272
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda