上一篇大恒相机的开发 是基于Qt Creator msvc工具链编译的,大恒相机msvc使用的的lib库是c++版的。如果想要使用mingw工具链开发大恒相机,那么找连接对相应的lib库。mingw对应的库是c的。
配置如下:
图像获取核心代码如下
void __stdcall Widget::OnFrameCallbackFun(GX_FRAME_CALLBACK_PARAM* pFrame)
{
Widget *pDlg = (Widget*)(pFrame->pUserParam);
int nImageHeight = pDlg->m_nImageHeight;
int nImageWidth = pDlg->m_nImageWidth;
if (pFrame->status == 0)
{
memcpy(pDlg->m_pBufferRaw,pFrame->pImgBuf,pFrame->nImgSize);
// 黑白相机需要翻转数据后显示
for(int i =0;i <nImageHeight;i++)
{
memcpy(pDlg->m_pImageBuffer+i*nImageWidth, pDlg->m_pBufferRaw+(nImageHeight-i-1)*nImageWidth,(size_t)nImageWidth);
}
//pDlg->DrawImg();
// 图像保存处理
QImage img(pDlg->m_pImageBuffer,pDlg->m_nImageWidth,pDlg->m_nImageHeight,QImage::Format_Indexed8);
emit pDlg->imageReady(img);
}
}
bool Widget::PrepareForShowImg()
{
//---------------------------------------------------------------------
//----------------------初始化bitmap头---------------------------------
m_pBmpInfo = (BITMAPINFO *)m_chBmpBuf;
m_pBmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
m_pBmpInfo->bmiHeader.biWidth = (LONG)m_nImageWidth;
m_pBmpInfo->bmiHeader.biHeight = (LONG)m_nImageHeight;
m_pBmpInfo->bmiHeader.biPlanes = 1;
m_pBmpInfo->bmiHeader.biBitCount = 8; // 黑白图像为8
m_pBmpInfo->bmiHeader.biCompression = BI_RGB;
m_pBmpInfo->bmiHeader.biSizeImage = 0;
m_pBmpInfo->bmiHeader.biXPelsPerMeter = 0;
m_pBmpInfo->bmiHeader.biYPelsPerMeter = 0;
m_pBmpInfo->bmiHeader.biClrUsed = 0;
m_pBmpInfo->bmiHeader.biClrImportant = 0;
// 黑白图像需要初始化调色板
for(int i=0;i<256;i++)
{
m_pBmpInfo->bmiColors[i].rgbBlue =i;
m_pBmpInfo->bmiColors[i].rgbGreen =i;
m_pBmpInfo->bmiColors[i].rgbRed =i;
m_pBmpInfo->bmiColors[i].rgbReserved=0;
}
//--------------------------------------------------------------------------
//------------------------图像数据Buffer分配---------------------------------
//为原始图像数据分配空间
m_pBufferRaw = new BYTE[(size_t)m_nPayLoadSize];
if (m_pBufferRaw == NULL)
{
return false;
}
//为经过翻转后的图像数据分配空间
m_pImageBuffer = new BYTE[(size_t)(m_nImageWidth * m_nImageHeight)];
if (m_pImageBuffer == NULL)
{
delete []m_pBufferRaw;
m_pBufferRaw = NULL;
return false;
}
return true;
}
有需要源码的话联系咸鱼号 solar.