我加载了一个位图,位图大小为7397*4164,256级灰度(问一下256级灰度和256色图像有差别吗?),为什么我读进来的位图数据,在用SetPixel()显示的时候不正确呢?当我加载1024*768位图的时候就没有这个问题,这里用考虑4字节的对齐问题吗?急死了!//这是读入位图的函数
void CImageView::OnImageIn()
{
memDC.SelectObject(oldObject);
m_pcbitmap.DeleteObject();
char szFilter[] = "Bitmap(*.BMP)|*.BMP||";
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFilter);
if(dlg.DoModal()==IDOK){
filename = dlg.GetPathName();
LoadBitmapFromFile(filename,m_pcbitmap);
}
m_pcbitmap.GetBitmap(m_pBitmap);
oldObject = memDC.SelectObject(&m_pcbitmap);
m_pcbBitmapBuffer = new char[m_pBitmap->bmWidth*m_pBitmap->bmHeight]; m_pcbitmap.GetBitmapBits( m_pBitmap->bmWidth*m_pBitmap->bmHeight, m_pcbBitmapBuffer ); ImageInFlag = 1;
}
//这是现实局部图像的函数
void CImageView::Inspection()
{
// TODO: Add your command handler code here
int height;
int width;char* rectbitmap;
InspectionBox = CRect(0,0,200,200);
height = InspectionBox.Height()+1;
width = InspectionBox.Width()+1;
CMainFrame* MainFrame=(CMainFrame*)this->GetParent()->GetParent();
CDefectView* DefectView=(CDefectView*)MainFrame->m_wndSplitter.GetPane(0,1);
CDC* DefectViewDC;
DefectViewDC = DefectView->GetDC(); for(int i=0;i<InspectionBox.Height();i++)
for(int j=0;j<InspectionBox.Width();j++)
{
int gray = m_pcbBitmapBuffer[i*m_pBitmap->bmWidth+j];//add CPoint pt(j,i);
DefectViewDC->SetPixel(pt,COLORREF(RGB(gray,gray,gray)));
}
}
当我把这个大小为7397*4164的位图,转成1024*768的就一切正常!什么原因呢?
void CImageView::OnImageIn()
{
memDC.SelectObject(oldObject);
m_pcbitmap.DeleteObject();
char szFilter[] = "Bitmap(*.BMP)|*.BMP||";
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFilter);
if(dlg.DoModal()==IDOK){
filename = dlg.GetPathName();
LoadBitmapFromFile(filename,m_pcbitmap);
}
m_pcbitmap.GetBitmap(m_pBitmap);
oldObject = memDC.SelectObject(&m_pcbitmap);
m_pcbBitmapBuffer = new char[m_pBitmap->bmWidth*m_pBitmap->bmHeight]; m_pcbitmap.GetBitmapBits( m_pBitmap->bmWidth*m_pBitmap->bmHeight, m_pcbBitmapBuffer ); ImageInFlag = 1;
}
//这是现实局部图像的函数
void CImageView::Inspection()
{
// TODO: Add your command handler code here
int height;
int width;char* rectbitmap;
InspectionBox = CRect(0,0,200,200);
height = InspectionBox.Height()+1;
width = InspectionBox.Width()+1;
CMainFrame* MainFrame=(CMainFrame*)this->GetParent()->GetParent();
CDefectView* DefectView=(CDefectView*)MainFrame->m_wndSplitter.GetPane(0,1);
CDC* DefectViewDC;
DefectViewDC = DefectView->GetDC(); for(int i=0;i<InspectionBox.Height();i++)
for(int j=0;j<InspectionBox.Width();j++)
{
int gray = m_pcbBitmapBuffer[i*m_pBitmap->bmWidth+j];//add CPoint pt(j,i);
DefectViewDC->SetPixel(pt,COLORREF(RGB(gray,gray,gray)));
}
}
当我把这个大小为7397*4164的位图,转成1024*768的就一切正常!什么原因呢?
解决方案 »
- 急 CTabCtrl继承类
- 关于在MFC中读取DIB文件
- 一个大家都遇到过的事情,很小很有趣!欢迎进来坐坐!
- 怎样获得“我的文档”、“我的电脑”、“网上邻居”系统图标?
- 串口正在通信的时候,如何改变串口设置?
- OnLButtonDown 需要处理太多的事情怎么办呢
- 对学习使用COM/ATL有心得的帮忙推荐几本书
- ADSL拨号,路由共享上网,如何取得路由器的外网IP?
- VC同VB,DELPHI,PB,BCB等工具相比,优势何在?
- 在vc中怎样调用word viewer 来打开一个doc 文档。
- vc2005中的"类向导"菜单命令在哪?
- OnPaint()函数,占了100%的cpu使用率,找不到问题,谢谢!
bmWidthBytes 每行数据多少个字节数