CFastImage::CFastImage(QWidget* parent) : QWidget(parent){ m_data=NULL; setAttribute( Qt::WA_PaintOnScreen, true); startTimer( 20);}CFastImage::~CFastImage(){ if(m_data!=NULL) delete[] m_data;}void CFastImage::timerEvent(QTimerEvent*){ update(); }void CFastImage::paintEvent(QPaintEvent* p){ // just for illustration purposes. You get the same effect if you leave the paint event completely empty, too. QWidget::paintEvent(p); BITMAPINFO BMP; BMP.bmiHeader.biWidth=width; BMP.bmiHeader.biHeight=height; BMP.bmiHeader.biBitCount=24; BMP.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); BMP.bmiHeader.biPlanes = 1; BMP.bmiHeader.biCompression = BI_RGB; BMP.bmiHeader.biSizeImage = ( ( BMP.bmiHeader.biWidth * ( BMP.bmiHeader.biBitCount >> 3 ) + 3 ) & - 4 ) * BMP.bmiHeader.biHeight; HDC hdc = GetDC(winId()); SetStretchBltMode( hdc, COLORONCOLOR ); StretchDIBits ( hdc , 0 , 0 , width , height , 0 , 0 , width , height , m_data , &BMP , DIB_RGB_COLORS , SRCCOPY ); ReleaseDC(winId(), hdc);}QPaintEngine* CFastImage::paintEngine() const{ return 0;}
#ifndef _FAST_IMAGE_H_#define _FAST_IMAGE_H_class CFastImage : public QWidget{public: CFastImage(QWidget* parent = NULL); ~CFastImage();public: virtual void timerEvent(QTimerEvent*); void paintEvent(QPaintEvent* p); QPaintEngine *paintEngine() const;public: unsigned char* m_data; int width; int height;};#endif //_FAST_IMAGE_H_