影像資料是別人傳過來的,我要顯示出來。使用的是16位的rgb資料,知道長寬,像素位等等資訊,但是構造完后,顯示不出來。有沒有大神可以指導下!~~~
BITMAPINFO bmpinfo={0};
bmpinfo.bmiHeader.biPlanes = 1;
bmpinfo.bmiHeader.biWidth=bmp.bmWidth;
bmpinfo.bmiHeader.biHeight=bmp.bmHeight;
bmpinfo.bmiHeader.biSizeImage=bmp.bmWidth*bmp.bmHeight;
bmpinfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
bmpinfo.bmiHeader.biCompression =BI_RGB;
bmpinfo.bmiHeader.biBitCount=16;
bmpinfo.bmiHeader.biClrUsed=0;
//bmiColors 這個不會用。。
bmpinfo.bmiColors->rgbReserved = 0;
bmpinfo.bmiColors->rgbRed = 0xFF;
bmpinfo.bmiColors->rgbGreen = 0xFF;
bmpinfo.bmiColors->rgbBlue = 0xFF;
HDC hDC = pDC->GetSafeHdc();
SetDIBitsToDevice (hDC,
0, // xDst
0, // yDst
bmp.bmWidth, // cxSrc
bmp.bmHeight, // cySrc
0 , // xSrc
0, // ySrc
0, // 從什么位置開始顯示dib
bmp.bmHeight, // 掃描多少行
bmp.bmBits, //指定從dib的什么位置開始掃描
&bmpinfo,
DIB_RGB_COLORS);
uj5u.com熱心網友回復:
R=R1/32*256G=G1/64*256
B=B1/32*256
進行轉換為24位資料
uj5u.com熱心網友回復:
除錯發現 SetDIBitsToDevice 這里根本沒有呼叫到,提示no executable code is associated with this line.possible causes include:preprocessor directives or compiler/linker optimizations
一臉懵逼啊啊啊啊 = =!
uj5u.com熱心網友回復:
// draw 16 bits bmp
void CShow256BmpDlg::OnButton4()
{
// TODO: Add your control notification handler code here
CClientDC dc(this); // device context for painting
CDC memDC;
CBitmap bitmap;
CBitmap bitmap1;
HBITMAP hBitmap;
HBITMAP OldBitmap;
DWORD len;
memDC.CreateCompatibleDC(&dc);
bitmap.LoadBitmap(IDB_BITMAP1);//16bit
//
BITMAP bm={0};
bitmap.GetBitmap(&bm);
int ImageSize=bm.bmWidthBytes * bm.bmHeight;
BYTE *pImageIn=new BYTE[ImageSize];
memset(pImageIn,0,ImageSize);
len=bitmap.GetBitmapBits(ImageSize,pImageIn);
// use: CreateDIBSection
BITMAPINFO bmInfo;
bmInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
bmInfo.bmiHeader.biWidth=bm.bmWidth;
bmInfo.bmiHeader.biHeight=-bm.bmHeight;// should '-' !!!!
bmInfo.bmiHeader.biPlanes=1;
bmInfo.bmiHeader.biBitCount=bm.bmBitsPixel;// =32
bmInfo.bmiHeader.biCompression=BI_RGB;
bmInfo.bmiHeader.biSizeImage=ImageSize;
bmInfo.bmiHeader.biXPelsPerMeter=0;
bmInfo.bmiHeader.biYPelsPerMeter=0;
bmInfo.bmiHeader.biClrUsed=0;
bmInfo.bmiHeader.biClrImportant=0;
void* tempArray=NULL;
hBitmap=::CreateDIBSection(dc.m_hDC, (BITMAPINFO*)&bmInfo,DIB_RGB_COLORS,&tempArray,NULL,0);
memcpy(tempArray,pImageIn,ImageSize);
//
OldBitmap=(HBITMAP)memDC.SelectObject(hBitmap);
dc.BitBlt(0,0,bm.bmWidth,bm.bmHeight,&memDC,0,0,SRCCOPY);
delete [] pImageIn;
}
bitmap.LoadBitmap(IDB_BITMAP1);//16bit
uj5u.com熱心網友回復:
那句 bitmap.LoadBitmap(IDB_BITMAP1);//16bit 也可以改為:HBITMAP hTmp=(HBITMAP)LoadImage (NULL, "16.bmp", IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE);
bitmap.Attach(hTmp);
/*
bmType 0
bmWidth 640
bmHeight 341
bmWidthBytes 1280
bmPlanes 1
bmBitsPixel 16
bmBits 0x02130000
*/
uj5u.com熱心網友回復:
注意memcpy(tempArray,pImageIn,ImageSize);
就是 把你的資料 放入 到 dib 中, 即 pImageIn 就是你輸入的 資料。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/120588.html
標籤:界面
