I've written a custom control to render images, since the default PictureBox led to a lot of lag. But I couldn't get rid of the stutter that happens when a new image is loaded.
The control is double buffered and uses the Paint event to draw the image manually:
Image img;
void ImageDrawer_Paint(object sender, PaintEventArgs e)
{
e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
var rect = new Rectangle(0, 0, img.Width, img.Height);
e.Graphics.DrawImage(img, rect);
}
The problem is that I'm trying to draw a video feed with about 30fps. This leads to the entire form lagging like crazy. When I set it to 1fps it's smooth, but when moving the window I can clearly feel a stutter every second.
Is there a faster way to draw an image to the screen? If I could get smooth performance with 30fps, that would be perfect.