我想显示在内存中生存的图像,但什么都看不到,请帮忙,谢谢!
OnShowDib() 
{
CClientDC dc(this) ;
BITMAPINFOHEADER bmiHeader;
bmiHeader.biSize =sizeof(BITMAPINFOHEADER);
bmiHeader.biWidth = 512;
bmiHeader.biHeight = 512;
bmiHeader.biPlanes = 1;
bmiHeader.biBitCount = 24;
bmiHeader.biCompression = BI_RGB;
bmiHeader.biSizeImage = 0;
bmiHeader.biXPelsPerMeter = 0;
bmiHeader.biYPelsPerMeter = 0;
bmiHeader.biClrUsed = 0;
bmiHeader.biClrImportant = 0; uchar *p = new uchar[512*512*3] ; long cs = 512*512 ; for ( int i = 0; i < cs ; i ++ )
{
uchar r = rand()%256 ;
uchar g = rand()%256 ;
uchar b = rand()%256 ;
*(p+i*3) = r ;
*(p+i*3 + 1) = g ;
*(p+i*3 + 2) = b ;
}
int nLine = ::StretchDIBits(dc.GetSafeHdc(),// nLine = 0
0,0,
512,512,
0,0,
512,512,
&p,
(LPBITMAPINFO)&bmiHeader,
DIB_RGB_COLORS,SRCCOPY);
delete[] p ;
}

解决方案 »

  1.   

    memset(&bmi, 0, sizeof(bmi));
        bmi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
        bmi.bmiHeader.biWidth       = ulJpgWidth;
        bmi.bmiHeader.biHeight      = -ulJpgHeight; // top-down image
        bmi.bmiHeader.biPlanes      = 1;
        bmi.bmiHeader.biBitCount    = 0;
        bmi.bmiHeader.biCompression = BI_JPEG;
        bmi.bmiHeader.biSizeImage   = nJpgImageSize;    //
        // Do the StretchDIBits.
        //    iRet = StretchDIBits(hdc,
                             // destination rectangle
                             ulDstX, ulDstY, ulDstWidth, ulDstHeight,
                             // source rectangle
                             0, 0, ulJpgWidth, ulJpgHeight,
                             pvJpgImage,
                             &bmi,
                             DIB_RGB_COLORS,
                             SRCCOPY);