为什么位图叠加文字后,字符是反的,是什么原因?

daisydew 2007-08-31 09:10:00
//在图片底部叠加文字
void TextInBmpFile2(BYTE *pBuf, int nImageWidth, int nImageHeight, const char *pText)
{
BITMAPINFOHEADER bmih;

memset(&bmih,0,sizeof(BITMAPINFOHEADER));
bmih.biSize = sizeof(BITMAPINFOHEADER);
bmih.biWidth = nImageWidth;
bmih.biHeight = nImageHeight;
bmih.biPlanes = 1;
bmih.biBitCount = 24;
bmih.biSizeImage = nImageWidth*nImageHeight*3;

HDC BmpDC;
HBITMAP hBitmap;
RECT rect;

memset(&rect, 0, sizeof(RECT));
rect.right = nImageWidth;
rect.bottom = nImageHeight;

BmpDC = CreateCompatibleDC(NULL);
hBitmap = CreateDIBitmap(GetDC(NULL), &bmih, CBM_INIT, pBuf, (BITMAPINFO*)&bmih, DIB_RGB_COLORS);

if (hBitmap) {
SelectObject(BmpDC, hBitmap);
// SetBkMode(BmpDC, TRANSPARENT);
DrawText(BmpDC, pText, strlen(pText), &rect, DT_SINGLELINE | DT_BOTTOM | DT_LEFT);
GetDIBits(BmpDC, hBitmap, 1, nImageHeight, pBuf, (BITMAPINFO*)&bmih, DIB_RGB_COLORS);
}
DeleteDC(BmpDC);
}

str.Format("%s | %-16s | %.2fkm/h ",
g_pView->CamInfo[nCurCam].strRoadName,
g_pView->m_vehrec.vehid,
nSpeed);
TextInBmpFile2(pByte, pFh->w, pFh->h, str);
pTemp = pByte;
pDstByte = pImageBuf;
memcpy(pImageBuf, pByte, nWidth * nHeight * 3);
...全文
319 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
daisydew 2007-09-01
  • 打赏
  • 举报
回复
是这样的,我从12bit的视频流里取出高8位一帧数据是对的,但直接从8bit的数据就不对了,显示在左上方,而且字体完全翻转过来,图像是正的,就不知是什么原因?是什么参数设置不对吗?所以想请教高人。
yesir1006 2007-09-01
  • 打赏
  • 举报
回复
对,就像 krh2001(边城浪子) 说的,不好意思,我一直用DIB的,忘了交代了。还有,我试了试你的程序,是显示在左下角的,不明白,请高人指点把
BITMAPINFOHEADER bmih;
memset(&bmih,0,sizeof(BITMAPINFOHEADER));
bmih.biSize = sizeof(BITMAPINFOHEADER);
bmih.biWidth = w;
bmih.biHeight = h;
bmih.biPlanes = 1;
bmih.biBitCount = 24;
bmih.biSizeImage = 3*w*h;

HDC BmpDC;
HBITMAP hBitmap;
RECT rect;

memset(&rect, 0, sizeof(RECT));
rect.right = w;
rect.bottom = h;

BmpDC = CreateCompatibleDC(NULL);
hBitmap = CreateDIBitmap(GetDC()->GetSafeHdc(), &bmih, CBM_INIT, im, (BITMAPINFO*)&bmih, DIB_RGB_COLORS);

BYTE* pIm = new unsigned char[w*h*3];
memset(pIm, 0, w*h*3);
if (hBitmap) {
SelectObject(BmpDC, hBitmap);
// SetBkMode(BmpDC, TRANSPARENT);
CString str = "try and try";
DrawText(BmpDC, str, strlen(str), &rect, DT_SINGLELINE | DT_BOTTOM | DT_LEFT);
GetDIBits(BmpDC, hBitmap, 1, h, pIm, (BITMAPINFO*)&bmih, DIB_RGB_COLORS);
StretchDIBits(pDC->GetSafeHdc(), 0, 0, w, h, 0, 0, w, h, pIm, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, SRCCOPY);
}
DeleteDC(BmpDC);
delete [] pIm;
jerry 2007-09-01
  • 打赏
  • 举报
回复
GetDIBits 读取的数据是 DIB数据, 和DDB不一样的, 上下相反的 不能这样做, 某些宽度的图像还会错位, 因为它们的 行字节对齐也不同.
yesir1006 2007-09-01
  • 打赏
  • 举报
回复
我是指对应于图像数据,图像的(0,0)点显示在左下角,(h-1,0)显示在左上角
jerry 2007-09-01
  • 打赏
  • 举报
回复
DIB 是 从左下角 开始的

DDB 是左上角开始的, 不一样的. 所以要注意怎么计算文字的位置
daisydew 2007-09-01
  • 打赏
  • 举报
回复
主要不是位置的意思,连文字都反了啊。
tracing 2007-09-01
  • 打赏
  • 举报
回复
左下角为(0, 0)?????????有没搞错
yesir1006 2007-09-01
  • 打赏
  • 举报
回复
在vc里,图像绘制的时候左下角为(0, 0),而不是左上角
daisydew 2007-08-31
  • 打赏
  • 举报
回复
DrawText可以设置回来吗?
daisydew 2007-08-31
  • 打赏
  • 举报
回复
本来是想在底部左边的,后来到顶部右边,图像没反,字符字体都反了,什么原因?

19,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧