CDC::StretchBltCopies a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap if necessary to fit the dimensions of the destination rectangle.OrCDC::FillSolidRectCall this member function to fill the given rectangle with the specified solid color.
use the GetRValue, GetGValue, and GetBValue macros, respectively
定义一个BITMAPINFO, 填写好对应的bmiHeader参数 这里的参数根据你的byte array来定义 比如RGB32的话就pbinfo->bmiHeader.biBitCount = 32; 然后调用CreateDIBSection来创建HBitmap 注意这里的第三个参数ppvBits 是out值有了HBitmap就好办了,要显示就太简单了。Google下还有种思路1、先声明一个BITMAP类型的变量如bitmap,并手工填充位图格式 2、用CreateBitmapIndirect()创建一个HBITMAP 3、用SetBitmapBits()或SetDIBits()为HBITMAP填充数据位 函数原形如下: LONG SetBitmapBits( HBITMAP hbmp, // handle to bitmap DWORD cBytes, // number of bytes in bitmap array CONST VOID *lpBits // array with bitmap bits ); HBITMAP CreateBitmapIndirect( CONST BITMAP *lpbm // bitmap data ); int SetDIBits( HDC hdc, // handle to DC HBITMAP hbmp, // handle to bitmap UINT uStartScan, // starting scan line UINT cScanLines, // number of scan lines CONST VOID *lpvBits, // array of bitmap bits CONST BITMAPINFO *lpbmi, // bitmap data UINT fuColorUse // type of color indexes to use );
我原以为::SetPixel(hDC, i, j, RGB(GetRValue(X), GetGValue(X), GetBValue(X));速度快,效果好, 看样子不是.
GetGValue //获取绿色分量的值
GetBValue //获取蓝色分量的值如
GetRValue(color);//COLORREF color = RGB(230,128,128);获取之后使用SetPixel或者SetPixelV都可以显示
pDstRGBBuf 是一个RGB数据 的指针。 以下不能把数据显示出来, 为什么? 要如何做?CWnd* pWnd = GetDlgItem(IDC_STATIC_BMP);
CDC* pDC = pWnd->GetDC();int nS = 0;
for (int i = 0; i < 176; i++)
for (int j = 0; j <144;j++ )
{
pDC->SetPixel(i, j, RGB(GetRValue((int)pDstRGBBuf + nS), GetGValue((int)pDstRGBBuf + nS + 1), GetBValue((int)pDstRGBBuf + nS + 2)) );
nS = nS + 3;
}
然后调用CreateDIBSection来创建HBitmap
注意这里的第三个参数ppvBits 是out值有了HBitmap就好办了,要显示就太简单了。Google下还有种思路1、先声明一个BITMAP类型的变量如bitmap,并手工填充位图格式
2、用CreateBitmapIndirect()创建一个HBITMAP
3、用SetBitmapBits()或SetDIBits()为HBITMAP填充数据位
函数原形如下:
LONG SetBitmapBits(
HBITMAP hbmp, // handle to bitmap
DWORD cBytes, // number of bytes in bitmap array
CONST VOID *lpBits // array with bitmap bits
);
HBITMAP CreateBitmapIndirect(
CONST BITMAP *lpbm // bitmap data
);
int SetDIBits(
HDC hdc, // handle to DC
HBITMAP hbmp, // handle to bitmap
UINT uStartScan, // starting scan line
UINT cScanLines, // number of scan lines
CONST VOID *lpvBits, // array of bitmap bits
CONST BITMAPINFO *lpbmi, // bitmap data
UINT fuColorUse // type of color indexes to use
);