How to write to a (Bitmap?) image buffer for faster GDI+ displays?

前端 未结 5 746
眼角桃花
眼角桃花 2021-01-07 11:14

Using C++ and .net I have a stream of data I want to display as a scrolling image. Each time I get some new data I want to add it as a new row (128x1 pixels) and scroll the

5条回答
  •  太阳男子
    2021-01-07 11:48

    A possible strategy:

    • Draw on a backbuffer from left to right which wraps around when reaching the end. Perform scrolling logic only when painting to screen (at some specified framerate). Use DrawImage with source rectangle and destination rectangle to achieve this.

    • Use bitmap.LockBits(...) and bitmap.UnlockBits(...) method to modify the raw Bitmap data. Be careful to only lock the rectangle you are going to modify, since these functions actually makes copies of the bitmap data from unmanaged to managed memory. An example on how to do this is described here Bitmap..::.LockBits Method (Rectangle, ImageLockMode, PixelFormat).

    • An alternative to LockBits is to use SetPixel on the bitmap. But SetPixel is known to be slow.

    • When blitting images to the screen make sure that CompositingMode on Graphics instance is set to bmpg.CompositingMode = CompositingMode.SourceCopy, and that pixel format of the back buffer is PixelFormat.Format32bppPArgb.

提交回复
热议问题