c# take picture with camera code example

Example 1: take screenshot in c#

using System.Windows.Forms; 
using Point = System.Drawing.Point;
using Rectangle = System.Drawing.Rectangle;
Rectangle bounds = Screen.GetBounds(Point.Empty);

using(Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
    using(Graphics g = Graphics.FromImage(bitmap))
    {
         g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
    }
    // will save to working directory  ( for C# WPF in VS 2019: C:\Users\{user}\source\repos\{project}\{project}\bin\Debug )
    bitmap.Save("test.jpg", ImageFormat.Jpeg);
}

Example 2: how to make a screen in python

import pygame
pygame.init()

sh = int(500)
sw = int(500)
win = pygame.display.set_mode((sh, sw))

run = True
while run:
    pygame.time.delay(100)
	for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

Tags:

Java Example