unsigned char *pTemp;
BYTE OsdY = 0;
BYTE OsdU = 0;
BYTE OsdV = 0;
void OSDSetTextColor(BYTE OsdR, BYTE OsdG, BYTE OsdB)
{
OsdY = 0.25*OsdR+0.504*OsdG+0.098*OsdB+16;
OsdU = -0.148*OsdR-0.291*OsdG+0.439*OsdB+128;
OsdV = 0.439*OsdR-0.368*OsdG-0.071*OsdB+128;
}
void CTest0Dlg::setOSD()
{
FILE *fp=fopen("d:\\temp\\OSD.bmp", "rb");
if(fp == 0)
return ;
HDC hDC = ::GetDC(GetSafeHwnd());
HDC hMemDC = CreateCompatibleDC(hDC);
fseek(fp, sizeof(BITMAPFILEHEADER), 0);
BITMAPINFOHEADER head;
fread(&head, sizeof(BITMAPINFOHEADER), 1, fp);
int bmpHeight = head.biHeight;
int bmpWidth = head.biWidth;
int biBitCount = head.biBitCount;
int lineByte = (bmpWidth*biBitCount/8+3)/4*4;
RGBQUAD *pColorTable;
unsigned char *pBmpBuf = new unsigned char[lineByte*bmpHeight];
fread(pBmpBuf, 1, lineByte*bmpHeight, fp);
memset(pBmpBuf,0, lineByte*bmpHeight);
CDC *m_pMemDC;
m_pMemDC = new CDC();
CDC *pDC;
pDC = GetDC();
m_pMemDC->CreateCompatibleDC(pDC);
CBitmap *m_pOldBmp = NULL;
CBitmap *m_pMemBmp = new CBitmap(); //根据图片的大小创建一个兼容位图
m_pMemBmp->CreateCompatibleBitmap(pDC, bmpWidth, bmpHeight);
m_pOldBmp = m_pMemDC->SelectObject(m_pMemBmp);
// 把图像的数据绘制到兼容位图上
SetDIBits(m_pMemDC->GetSafeHdc(), (HBITMAP)m_pMemBmp->m_hObject,
0, bmpHeight, (LPVOID)pBmpBuf, (BITMAPINFO*)&head, DIB_RGB_COLORS);
m_pMemDC->SetBkMode(TRANSPARENT);
m_pMemDC->SetTextColor(RGB(255, 0, 0));//RGB标记色
OSDSetTextColor(0, 0, 0);//OSD显示色
//设置字体
CFont font;
font.CreateFont(20,15,0,0,10,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_DEFAULT_PRECIS,OUT_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_SWISS,"宋体");
SelectObject(hMemDC, font);
///////////////////////////
SYSTEMTIME st;
CString strDate,strTime;
GetLocalTime(&st);
strDate.Format("时间 %04d-%02d-%02d ",st.wYear,st.wMonth,st.wDay);
strTime.Format("%02d:%02d:%02d",st.wHour,st.wMinute,st.wSecond);
// 添加文字到指定位置
m_pMemDC->TextOut(20, 40, strDate+strTime);
pTemp = new unsigned char[lineByte*bmpHeight];
GetDIBits(m_pMemDC->GetSafeHdc(), (HBITMAP)m_pMemBmp->m_hObject, 0, bmpHeight,
(LPVOID)pTemp, (BITMAPINFO*)&head, DIB_RGB_COLORS);
fclose(fp);
delete m_pMemBmp;
delete m_pMemDC;
delete[] pBmpBuf;
//MessageBox("VOER!");
}
调用部分
//////////////////////////////////////////////////////////////////////////////////////
setOSD();
for (int i=0;i<80;i++)
{
for (int k=0;k<640;k++)
{
//dc.SetPixel(k,79-i,RGB(pTemp[(i*640+k)*3+2],pTemp[(i*640+k)*3+1],pTemp[(i*640+k)*3+0]));
if (pTemp[(i*640+k)*3+2]!=0)//需要叠加 通过标记色过滤
{
pFrameYUV->data[0][(79-i)*720+k]=OsdY;
if((79-i)%2==0)
{
pFrameYUV->data[1][(79-i)*720/4+k/2]=OsdU;
pFrameYUV->data[2][(79-i)*720/4+k/2]=OsdV;
}
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////
memcpy(image->pixels[0], pFrameYUV->data[0],720*576);//拷贝数据yuv420,也可预先改变指针
memcpy(image->pixels[2], pFrameYUV->data[1],720*576/4);
memcpy(image->pixels[1], pFrameYUV->data[2],720*576/4);
。。。。。。。。。。。。。。。。。。。。。。。。。