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

前端 未结 5 783
眼角桃花
眼角桃花 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:36

    I'm not quite clear on exactly what you're trying to draw (some kind of control on a dialog?) but at a guess it should work something like:

    class Foo {
        ...
        Gdiplus::Bitmap* m_pBitmap;
    };
    
    void Foo::DrawItem(LPDRAWITEMSTRUCT lpDraw) {
    
       // update bitmap if needed
       if(some_condition_requiring_bitmap_redraw) {
    
           // do expensive drawing into bitmap
           Gdiplus::Graphics graphics(m_pBitmap);
       }
    
    
       // create a graphics object to draw the control from the bitmap
       Gdiplus::Graphics graphics(lpDraw->hDC);
       graphics.DrawImage(m_pBitmap, ...);
    }
    

    That's a very rough guess at it anyway. The DrawItem call might look quite different if you're using .NET (I'm not familiar with it...), but the basic logic should be approximately the same.

    Depending on what exactly your data is, it may not be efficient to draw 1 pixel rows at a time. You may be better off drawing a large area and only showing bits of it as required - although that will obviously depend on how your data comes in.

    You also might need to do some kind of update to your bitmap to "scroll" its contents. I'll leave that up to you :-)

提交回复
热议问题