コード例 #1
0
void CVideoClientDlg::OnLoadPNG(LPCTSTR Path, CRect m_Rect)
{
	ATL::CImage img;
	HRESULT ret = img.Load(Path); //要加载的图片名称,包含路径
	HBITMAP hbitmap = img.Detach();

	//像操作 BMP 图片一样处理图片 ,下面是显示图片的操作
	CPaintDC dc(this);// 用于绘制的设备上下文
	CRect rect;    
	GetClientRect(&rect);  
	CBitmap pngBackground;
	BITMAP bitmap;
	CDC memdc;
	pngBackground.Attach(hbitmap);
	memdc.CreateCompatibleDC(&dc);
	pngBackground.GetBitmap(&bitmap);  //建立绑定关系  
	CBitmap  *pbmpOld=memdc.SelectObject(&pngBackground);   //保存原有CDC对象,并选入新CDC对象入DC  
	dc.SetStretchBltMode(COLORONCOLOR);//防止bmp图片失真
	dc.StretchBlt(0,0,rect.Width(),rect.Height(),&memdc,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);
	memdc.SelectObject(pbmpOld);

	//程治谦 2015-1-13 防止内存泄漏
	(*pbmpOld).DeleteObject();
	DeleteObject(hbitmap);
	img.Destroy();
	pngBackground.DeleteObject();  
	memdc.DeleteDC(); 
}
コード例 #2
0
void CVideoClientDlg::OnPaint()
{
	CRect rect;
	m_sdlPlayer.GetWindowRect(&rect);
	OnLoadPNG(_T(g_szOcxPath+"res/ui-mockup-player-bg1.png"), rect);

	//程治谦 2015-1-13 防止内存泄漏
	//CStatic* pWnd = (CStatic*)GetDlgItem(IDCSDLPLAYER); // 得到 Picture Control 句柄  

	ATL::CImage image;  
	image.Load(_T(g_szOcxPath+"res/ui-mockup-player-inner.png"));  
	HBITMAP hBmp = image.Detach();  
	m_sdlPlayer.SetBitmap(hBmp);

	//程治谦 2015-1-13 防止内存泄漏
	DeleteObject(hBmp);
	image.Destroy();
}
コード例 #3
0
ファイル: Camera.cpp プロジェクト: Strongc/camera
/****************************************************************************

说明      将内存m_pImageBuffer 转换 CImage

****************************************************************************/
int HV_Camera::getcimage(ATL::CImage &CI)
{
	ConvertBayer2Rgb(m_pImageBuffer,m_pRawBuffer,Width,Height,ConvertType,
									m_pLutR,m_pLutG,m_pLutB,false,m_Layout);
	CI.Create( Width , -Height, 8*3);// If Height is negative, the bitmap is a top-down DIB and its origin is the upper left corner.
	
	uchar *pImg=(uchar *)CI.GetBits();//得到CImage数据区地址

	memcpy(pImg,m_pImageBuffer,Width*Height*3);
	//int step=CI.GetPitch();
	//for(int i=0;i<Height;i++)
	//{
	//	//pS=imgShow.ptr<uchar>(i);
	//	for(int j=0;j<Width;j++)
	//	{
	//		for(int k=0;k<3;k++)
	//			*(pImg+i*step+j*3+k)=m_pImageBuffer[i*(step)+j*3+k];
	//	}
	//}
	return 1;
}
コード例 #4
0
void  CvvImage::DrawMatToHDC(Mat mat, HDC hDC, RECT rect)
{
    ATL::CImage img; //ATL::CImage
    int w = mat.cols;  //宽
    int h = mat.rows;  //高
    int chinnels = mat.channels();
    img.Create(w, h, chinnels << 3);

    RGBQUAD* pColorTable = NULL;
    int nMaxColors = 256;
    pColorTable = new RGBQUAD[nMaxColors];
    img.GetColorTable(0, nMaxColors, pColorTable);

    for(int i = 0; i < nMaxColors; i++)
    {
        pColorTable->rgbBlue = (BYTE) i;
        pColorTable->rgbGreen = (BYTE) i;
        pColorTable->rgbRed = (BYTE) i;
    }

    img.SetColorTable(0, nMaxColors, pColorTable);
    delete[] pColorTable;

    int i, j, k;
    BYTE *pSource = NULL;
    BYTE *pImgData = (BYTE *) img.GetBits();
    int step = img.GetPitch();

    if(chinnels == 1)
    {
        for(i = 0; i < h; ++i)
        {
            pSource = mat.ptr<BYTE> (i);

            for(j = 0; j < w; ++j)
            {
                * (pImgData + i * step + j) = pSource[j];
            }
        }
    }
    else if(chinnels == 3)
    {
        for(i = 0; i < h; ++i)
        {
            pSource = mat.ptr<BYTE> (i);

            for(j = 0; j < w; ++j)
            {
                for(k = 0; k < 3; ++k)
                {
                    * (pImgData + i * step + j * 3 + k) = pSource[j * 3 + k];
                }
            }
        }
    }
    else
    {
        AfxMessageBox(TEXT("仅支持灰度图/3通道彩色图"));
        return;
    }

    SetStretchBltMode(hDC, COLORONCOLOR);
    img.StretchBlt(hDC, rect, SRCCOPY);
    img.Destroy();
}