C# Update bitmap in picturebox

后端 未结 3 1372
再見小時候
再見小時候 2021-02-19 18:17

I\'m working on a screen sharing project ,and i recieve a small blocks of image from a Socket constantly and need to update them on a certain initial dekstop bitmap

3条回答
  •  感情败类
    2021-02-19 18:41

    If you just need to draw on top of the canvas, you can draw the initial image just once and then use CreateGraphics() and DrawImage to update the content:

    ReadData();
    initial = bufferToJpeg();
    pictureBox1.Image = initial;
    var graphics = pictureBox1.CreateGraphics();
    while (true)
    {
        int pos = ReadData();
        Bitmap block = bufferToJpeg();
        graphics.DrawImage(block, BlockX(), BlockY());
    }
    

    I'll update the answer with a performance comparison as I'm not convinced this will give any major benefit; it will, at least, avoid a double DrawImage though.

提交回复
热议问题