0

I'm making a wpf application that will record the screen or take a screen shot. I figure out how to take a screen shot and also I show screen in the application. But I couldn't find how to create a video with them.

This is code that I'm screen shot the screen:

private BitmapImage CaptureScreen() {

    System.Drawing.Rectangle screenSize = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
    Trace.WriteLine(screenSize.Width);
    Trace.WriteLine(screenSize.Height);
    System.Drawing.Bitmap target = new System.Drawing.Bitmap(screenSize.Width, screenSize.Height);
    using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(target)) {
        g.CopyFromScreen(0, 0, 0, 0, new System.Drawing.Size(screenSize.Width, screenSize.Height));
    }
        
    BitmapImage bitmapImage = new BitmapImage();
    using (MemoryStream memory = new MemoryStream()) {
        target.Save(memory, ImageFormat.Png);
        memory.Position = 0;
        bitmapImage.BeginInit();
        bitmapImage.StreamSource = memory;
        bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
        bitmapImage.EndInit();
    }

    return bitmapImage;
}

This is code that how I'm record:

DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(Events);
dispatcherTimer.Start();

private void Events(object sender, EventArgs e) {        
    // ScreenImage is an image that I'm using for see what app is recording
    ScreenImage.Source = CaptureScreen();
}

Finnaly what I'm asking is :

I need to write a video file from image that I take from CaptureScreen()

  • So... what is your question? – Dai Aug 14 '22 at 21:11
  • There is a [closely related post](https://stackoverflow.com/q/9744026/1911064) you might want to have a look at. – Axel Kemper Aug 14 '22 at 21:58
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Aug 15 '22 at 14:48

0 Answers0