Quiero capturar la pantalla en mi código para obtener una imagen, como usar el botón 'imprimir pantalla' en el teclado.Capturar la pantalla en un mapa de bits
¿Alguien tiene una idea de cómo hacer esto? No tengo punto de partida
Quiero capturar la pantalla en mi código para obtener una imagen, como usar el botón 'imprimir pantalla' en el teclado.Capturar la pantalla en un mapa de bits
¿Alguien tiene una idea de cómo hacer esto? No tengo punto de partida
Si el uso del marco .NET 2.0 (o posterior), puede utilizar el método CopyFromScreen()
se detalla aquí:
http://www.geekpedia.com/tutorial181_Capturing-screenshots-using-Csharp.html
//Create a new bitmap.
var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height,
PixelFormat.Format32bppArgb);
// Create a graphics object from the bitmap.
var gfxScreenshot = Graphics.FromImage(bmpScreenshot);
// Take the screenshot from the upper left corner to the right bottom corner.
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
Screen.PrimaryScreen.Bounds.Y,
0,
0,
Screen.PrimaryScreen.Bounds.Size,
CopyPixelOperation.SourceCopy);
// Save the screenshot to the specified path that the user has chosen.
bmpScreenshot.Save("Screenshot.png", ImageFormat.Png);
// Use this version to capture the full extended desktop (i.e. multiple screens)
Bitmap screenshot = new Bitmap(SystemInformation.VirtualScreen.Width,
SystemInformation.VirtualScreen.Height,
PixelFormat.Format32bppArgb);
Graphics screenGraph = Graphics.FromImage(screenshot);
screenGraph.CopyFromScreen(SystemInformation.VirtualScreen.X,
SystemInformation.VirtualScreen.Y,
0,
0,
SystemInformation.VirtualScreen.Size,
CopyPixelOperation.SourceCopy);
screenshot.Save("Screenshot.png", System.Drawing.Imaging.ImageFormat.Png);
Su código no muestra una imagen adecuada. ¿Se supone que es un JPEG o un PNG? –
Funciona bien, pero hay una congelación de IU general. Incompatible para proyectos (como el mío) que necesitan analizar la pantalla 10-20 veces por segundo. – Jurion
Trate this código
Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics gr = Graphics.FromImage(bmp);
gr.CopyFromScreen(0, 0, 0, 0, bmp.Size);
pictureBox1.Image = bmp;
bmp.Save("img.png",System.Drawing.Imaging.ImageFormat.Png);
Bitmap memoryImage;
//Set full width, height for image
memoryImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height,
PixelFormat.Format32bppArgb);
Size s = new Size(memoryImage.Width, memoryImage.Height);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
memoryGraphics.CopyFromScreen(0, 0, 0, 0, s);
string str = "";
try
{
str = string.Format(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
@"\Screenshot.png");//Set folder to save image
}
catch { };
memoryImage.save(str);
Se recomienda agregar alguna explicación a su código para que las personas que lean su respuesta lo entiendan mejor y más fácil. – Ibo
Agradable y simple ... funciona como un encanto ... ¡gracias! –
Su respuesta es incorrecto por favor actualizarlo con (g.CopyFromScreen ( 0, 0 , 0, 0 , Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy); –
Pero, ¿funciona en múltiples monitores pc – EaterOfCode