DIBitmap
-
int the function OnDraw();I want to create a DIB bitmap using the array pData,and display it on the screen,but I am not fail to do it;Would please tell me how to correct the codes below. //the array containing color information unsigned char* pData=new unsigned char[768*576*3]; int y=0, x=0; for(;y<576;y++) for(;x<768;x++) { pData[x*3+y*768*3]=0; pData[x*3+1+y*768*3]=0; pData[x*3+2+y*768*3]=255; } //information header BITMAPINFOHEADER FrameBmi; FrameBmi.biSize=sizeof(BITMAPINFOHEADER); FrameBmi.biPlanes=1; FrameBmi.biCompression=BI_RGB; FrameBmi.biClrImportant=0; FrameBmi.biSizeImage=768*576*3; FrameBmi.biClrUsed=0; FrameBmi.biBitCount=24; FrameBmi.biWidth=768; FrameBmi.biHeight=576; FrameBmi.biXPelsPerMeter = 0; FrameBmi.biYPelsPerMeter =0; //file header BITMAPFILEHEADER pf; pf.bfType=0x4d42; //"BM" pf.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+sizeof(char[768*576]); pf.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); pf.bfReserved1=0; pf.bfReserved2=0; //BITMAPINFOHEADER LPBITMAPINFO lpbmi=(LPBITMAPINFO)GlobalAlloc(GMEM_FIXED,sizeof(BITMAPINFOHEADER)); ASSERT(lpbmi); lpbmi->bmiHeader.biSize=FrameBmi.biSize; lpbmi->bmiHeader.biPlanes=FrameBmi.biPlanes; lpbmi->bmiHeader.biCompression=FrameBmi.biCompression; lpbmi->bmiHeader.biClrImportant=FrameBmi.biClrImportant; lpbmi->bmiHeader.biSizeImage=FrameBmi.biSizeImage; lpbmi->bmiHeader.biClrUsed=FrameBmi.biClrUsed; lpbmi->bmiHeader.biBitCount=FrameBmi.biBitCount; lpbmi->bmiHeader.biWidth=FrameBmi.biWidth; lpbmi->bmiHeader.biHeight=FrameBmi.biHeight; lpbmi->bmiHeader.biXPelsPerMeter=FrameBmi.biXPelsPerMeter; lpbmi->bmiHeader.biYPelsPerMeter=FrameBmi.biYPelsPerMeter; lpbmi->bmiColors=NULL; //Create DIBitmap CBitmap *OldBitmap; HBITMAP bmp =::CreateDIBitmap((HDC)pDC,&FrameBmi,CBM_INIT,pData,lpbmi, DIB_RGB_COLORS); ASSERT(bmp); // CBitmap bitmap; bitmap.Attach(bmp); CDC dcComp; dcComp.CreateCompatibleDC(pDC); OldBitmap=dcComp.SelectObject(&bitmap); BITMAP bm; bitmap.GetObject(sizeof(BITMAP),&bm); // draw bitmap pDC->BitBlt(0,0,768,576,&dcComp,0,0,SRCCOPY); dcComp.SelectObject(OldBitmap); delete [] pData; GlobalFree(lpbmi); delteDC(dcComp); I LOVE VC -- modified at 6:43 Sunday 16th October, 2005
-
int the function OnDraw();I want to create a DIB bitmap using the array pData,and display it on the screen,but I am not fail to do it;Would please tell me how to correct the codes below. //the array containing color information unsigned char* pData=new unsigned char[768*576*3]; int y=0, x=0; for(;y<576;y++) for(;x<768;x++) { pData[x*3+y*768*3]=0; pData[x*3+1+y*768*3]=0; pData[x*3+2+y*768*3]=255; } //information header BITMAPINFOHEADER FrameBmi; FrameBmi.biSize=sizeof(BITMAPINFOHEADER); FrameBmi.biPlanes=1; FrameBmi.biCompression=BI_RGB; FrameBmi.biClrImportant=0; FrameBmi.biSizeImage=768*576*3; FrameBmi.biClrUsed=0; FrameBmi.biBitCount=24; FrameBmi.biWidth=768; FrameBmi.biHeight=576; FrameBmi.biXPelsPerMeter = 0; FrameBmi.biYPelsPerMeter =0; //file header BITMAPFILEHEADER pf; pf.bfType=0x4d42; //"BM" pf.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+sizeof(char[768*576]); pf.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); pf.bfReserved1=0; pf.bfReserved2=0; //BITMAPINFOHEADER LPBITMAPINFO lpbmi=(LPBITMAPINFO)GlobalAlloc(GMEM_FIXED,sizeof(BITMAPINFOHEADER)); ASSERT(lpbmi); lpbmi->bmiHeader.biSize=FrameBmi.biSize; lpbmi->bmiHeader.biPlanes=FrameBmi.biPlanes; lpbmi->bmiHeader.biCompression=FrameBmi.biCompression; lpbmi->bmiHeader.biClrImportant=FrameBmi.biClrImportant; lpbmi->bmiHeader.biSizeImage=FrameBmi.biSizeImage; lpbmi->bmiHeader.biClrUsed=FrameBmi.biClrUsed; lpbmi->bmiHeader.biBitCount=FrameBmi.biBitCount; lpbmi->bmiHeader.biWidth=FrameBmi.biWidth; lpbmi->bmiHeader.biHeight=FrameBmi.biHeight; lpbmi->bmiHeader.biXPelsPerMeter=FrameBmi.biXPelsPerMeter; lpbmi->bmiHeader.biYPelsPerMeter=FrameBmi.biYPelsPerMeter; lpbmi->bmiColors=NULL; //Create DIBitmap CBitmap *OldBitmap; HBITMAP bmp =::CreateDIBitmap((HDC)pDC,&FrameBmi,CBM_INIT,pData,lpbmi, DIB_RGB_COLORS); ASSERT(bmp); // CBitmap bitmap; bitmap.Attach(bmp); CDC dcComp; dcComp.CreateCompatibleDC(pDC); OldBitmap=dcComp.SelectObject(&bitmap); BITMAP bm; bitmap.GetObject(sizeof(BITMAP),&bm); // draw bitmap pDC->BitBlt(0,0,768,576,&dcComp,0,0,SRCCOPY); dcComp.SelectObject(OldBitmap); delete [] pData; GlobalFree(lpbmi); delteDC(dcComp); I LOVE VC -- modified at 6:43 Sunday 16th October, 2005
daojinliu wrote:
but I am not successful
what happens ?? Cleek | Image Toolkits | Thumbnail maker
-
daojinliu wrote:
but I am not successful
what happens ?? Cleek | Image Toolkits | Thumbnail maker
-
I got a error that there was a ASSERT error in the line of "CreateDIBitmap()", I am fail to create a DIB bitmap and display it in the monitor. I LOVE VC
try calling GetLastError just after CreateDIBitmap Cleek | Image Toolkits | Thumbnail maker
-
I got a error that there was a ASSERT error in the line of "CreateDIBitmap()", I am fail to create a DIB bitmap and display it in the monitor. I LOVE VC
pData is too small for the bitmap you are trying to create.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!
-
pData is too small for the bitmap you are trying to create.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!
-
yes,the pData should be pData=new unsigned char[768*576*3],but after above update,I am fail to create the DIB bitmap again, I LOVE VC
::CreateBitmap(pDC->m_hDC, ...
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!