Create Bitmap From buffer
-
I got pbuffer from a camera device. Now i have to make bitmap and show in thumnail view. LPBYTE pBuffer=new BYTE[height*width*3]; memcpy(pBuffer,(LPBYTE)lParam,height*width*3); what i did: DrawThumbnails(){ CBitmap* pImage = NULL; HBITMAP hBitmap = NULL; HDC hMemDC = NULL; HGDIOBJ hOldObj = NULL; POINT pt; int x, i; // = m_ImageListThumb.GetImageCount(); CString str; str.Format("%d",pBuffer); AfxMessageBox(str); // no images // set the length of the space between thumbnails // you can also calculate and set it based on the length of your list control int nGap = 6; // hold the window update to avoid flicking m_ListThumbnail.SetRedraw(FALSE); // reset our image list // for( i=0; im_hWnd; // create thumbnail bitmap section bih.biWidth = THUMBNAIL_WIDTH; bih.biHeight = THUMBNAIL_HEIGHT; // hBitmap = CreateBitmapIndirect(&bitmap); hBitmap = ::CreateDIBSection(NULL,&bmi, DIB_RGB_COLORS, NULL, NULL, 0); //hBitmap = ::CreateDIBitmap(hDC,&bih,CBM_INIT,pBuffer,(BITMAPINFO*)&bih,DIB_RGB_COLORS); //hBitmap = CreateBitmap(m_nWidth,m_nHeight,1,24,) // restore dib header //dib.m_pBMI->bmiHeader.biWidth = nWidth; //dib.m_pBMI->bmiHeader.biHeight = nHeight; bih.biWidth= m_nWidth; bih.biHeight = m_nHeight; // select thumbnail bitmap into screen dc
-
I got pbuffer from a camera device. Now i have to make bitmap and show in thumnail view. LPBYTE pBuffer=new BYTE[height*width*3]; memcpy(pBuffer,(LPBYTE)lParam,height*width*3); what i did: DrawThumbnails(){ CBitmap* pImage = NULL; HBITMAP hBitmap = NULL; HDC hMemDC = NULL; HGDIOBJ hOldObj = NULL; POINT pt; int x, i; // = m_ImageListThumb.GetImageCount(); CString str; str.Format("%d",pBuffer); AfxMessageBox(str); // no images // set the length of the space between thumbnails // you can also calculate and set it based on the length of your list control int nGap = 6; // hold the window update to avoid flicking m_ListThumbnail.SetRedraw(FALSE); // reset our image list // for( i=0; im_hWnd; // create thumbnail bitmap section bih.biWidth = THUMBNAIL_WIDTH; bih.biHeight = THUMBNAIL_HEIGHT; // hBitmap = CreateBitmapIndirect(&bitmap); hBitmap = ::CreateDIBSection(NULL,&bmi, DIB_RGB_COLORS, NULL, NULL, 0); //hBitmap = ::CreateDIBitmap(hDC,&bih,CBM_INIT,pBuffer,(BITMAPINFO*)&bih,DIB_RGB_COLORS); //hBitmap = CreateBitmap(m_nWidth,m_nHeight,1,24,) // restore dib header //dib.m_pBMI->bmiHeader.biWidth = nWidth; //dib.m_pBMI->bmiHeader.biHeight = nHeight; bih.biWidth= m_nWidth; bih.biHeight = m_nHeight; // select thumbnail bitmap into screen dc
you don't say what the error is, or what results you're getting. but, i see one big problem: CreateDIBitmap and CreateDIBSection require that the pixels are arranged the way they are arranged in a DIB: 1. rows are ordered bottom-up 2. rows are padded to multiples of 4 bytes each 3. RGB pixels are in BGR color order your buffer of w * h * 3 pixels is almost certainly not accounting for requirement 2.
image processing toolkits | batch image processing | blogging