求解bmp格式图片转化成二维数组源码 把一张bmp格式图片转化成二维数组并写入txt文件,黑色像素设为1,白色像素设为0,红色设为2,绿色设为3.最好用vc++!谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参考图像转换成字符void CPictureToTextDlg::OnConvert() { //BITMAPINFOHEADER infoheader; CPaintDC dc(this); long* m_pbmpdata; long* p_tmp; BITMAPINFO *m_pbmpinfo,m_bmp; HBITMAP hbmp=(HBITMAP)LoadImage(::AfxGetResourceHandle(),"bitmap.bmp", IMAGE_BITMAP,0, 0,LR_DEFAULTCOLOR|LR_LOADFROMFILE); m_bmp.bmiHeader.biSize=sizeof(m_bmp.bmiHeader); m_bmp.bmiHeader.biBitCount=0; int bmpWidth; int bmpHeight; GetDIBits(dc.GetSafeHdc(),hbmp,0,1,NULL,&m_bmp,DIB_RGB_COLORS); bmpWidth=m_bmp.bmiHeader.biWidth; bmpHeight=m_bmp.bmiHeader.biHeight; p_tmp=(long*)malloc(bmpWidth*bmpHeight*m_bmp.bmiHeader.biBitCount+sizeof(BITMAPINFO)); m_pbmpinfo=(BITMAPINFO*)p_tmp; m_pbmpdata=p_tmp+sizeof(BITMAPINFO); memcpy(p_tmp,(const void*)&m_bmp,sizeof(BITMAPINFOHEADER)); GetDIBits(dc.GetSafeHdc(),hbmp,0,m_bmp.bmiHeader.biHeight,m_pbmpdata, m_pbmpinfo,DIB_RGB_COLORS); /* BITMAPINFOHEADER RGB32BITSBITMAPINFO= {sizeof(BITMAPINFOHEADER),m_bmp.bmiHeader.biWidth,m_bmp.bmiHeader.biHeight, 1,32,BI_RGB,0,0,0,0}; SetDIBitsToDevice(dc.GetSafeHdc(),10,10,bmpWidth, bmpHeight,0,0,0,bmpHeight, m_pbmpdata,(LPBITMAPINFO)&RGB32BITSBITMAPINFO,DIB_RGB_COLORS); */ long lngBackColor=RGB(255,255,255); long lTemp; int r,g,b; CString strChar,strTemp; for(int i=bmpHeight;i>1;i--) { for(int j=1;j<bmpWidth;j++) { lTemp=m_pbmpdata[(j-1)+(i-1)*bmpWidth]; r=GetRValue(lTemp); g=GetGValue(lTemp); b=GetBValue(lTemp); if(r>224 || g >224 || r >224) strChar=" "; else if(r>192 || g >192 || r >192 ) strChar="#"; else if(r>160 || g >160 || r >160 ) strChar="%"; else if(r>128 || g >128 || r >128 ) strChar="$"; else if(r>96 || g >96 || r >96 ) strChar="8"; else if(r>64 || g >64 || r >64 ) strChar="X"; else if(r>32 || g >32 || r >32 ) strChar="?"; else strChar="?"; m_edit.GetWindowText(strTemp); strTemp=strTemp+strChar; m_edit.SetWindowText(strTemp); /* if(r>224 || g >224 || r >224) strChar="?"; else if(r>192 || g >192 || r >192 ) strChar="?"; else if(r>160 || g >160 || r >160 ) strChar="X"; else if(r>128 || g >128 || r >128 ) strChar="8"; else if(r>96 || g >96 || r >96 ) strChar="$"; else if(r>64 || g >64 || r >64 ) strChar="%"; else if(r>32 || g >32 || r >32 ) strChar="#"; else strChar="@"; */ } m_edit.GetWindowText(strTemp); strTemp=strTemp+"\r\n"; m_edit.SetWindowText(strTemp); }} 如何将两编辑框操作后的内容赋给第三个编辑框 如何让程序运行起来? directshow 接收RTPlib多路数据的问题 OCX调用DLL报Unhandled exception in IEXPLORE:0xC0000005:Access Violation 修改OCX的敏感问题 动态二维字符串数组如何定义,赋值,访问? 怎么样枚举系统中所有进程的窗体?包括托盘里面的程序! 【公务】版主删帖记录专用帖 关于内存分配的问题? CSDN上有中科院计算所的研究生吗(在读或毕业) 如何防止ICMP数据包被截获? ClistCtrl自画出现问题?
void CPictureToTextDlg::OnConvert()
{
//BITMAPINFOHEADER infoheader;
CPaintDC dc(this);
long* m_pbmpdata;
long* p_tmp;
BITMAPINFO *m_pbmpinfo,m_bmp;
HBITMAP hbmp=(HBITMAP)LoadImage(::AfxGetResourceHandle(),"bitmap.bmp",
IMAGE_BITMAP,0, 0,LR_DEFAULTCOLOR|LR_LOADFROMFILE);
m_bmp.bmiHeader.biSize=sizeof(m_bmp.bmiHeader);
m_bmp.bmiHeader.biBitCount=0; int bmpWidth;
int bmpHeight;
GetDIBits(dc.GetSafeHdc(),hbmp,0,1,NULL,&m_bmp,DIB_RGB_COLORS);
bmpWidth=m_bmp.bmiHeader.biWidth;
bmpHeight=m_bmp.bmiHeader.biHeight;
p_tmp=(long*)malloc(bmpWidth*bmpHeight*m_bmp.bmiHeader.biBitCount+sizeof(BITMAPINFO));
m_pbmpinfo=(BITMAPINFO*)p_tmp;
m_pbmpdata=p_tmp+sizeof(BITMAPINFO);
memcpy(p_tmp,(const void*)&m_bmp,sizeof(BITMAPINFOHEADER));
GetDIBits(dc.GetSafeHdc(),hbmp,0,m_bmp.bmiHeader.biHeight,m_pbmpdata,
m_pbmpinfo,DIB_RGB_COLORS);
/*
BITMAPINFOHEADER RGB32BITSBITMAPINFO=
{sizeof(BITMAPINFOHEADER),m_bmp.bmiHeader.biWidth,m_bmp.bmiHeader.biHeight,
1,32,BI_RGB,0,0,0,0};
SetDIBitsToDevice(dc.GetSafeHdc(),10,10,bmpWidth,
bmpHeight,0,0,0,bmpHeight,
m_pbmpdata,(LPBITMAPINFO)&RGB32BITSBITMAPINFO,DIB_RGB_COLORS);
*/ long lngBackColor=RGB(255,255,255);
long lTemp;
int r,g,b;
CString strChar,strTemp;
for(int i=bmpHeight;i>1;i--)
{
for(int j=1;j<bmpWidth;j++)
{
lTemp=m_pbmpdata[(j-1)+(i-1)*bmpWidth]; r=GetRValue(lTemp);
g=GetGValue(lTemp);
b=GetBValue(lTemp); if(r>224 || g >224 || r >224)
strChar=" ";
else if(r>192 || g >192 || r >192 )
strChar="#";
else if(r>160 || g >160 || r >160 )
strChar="%";
else if(r>128 || g >128 || r >128 )
strChar="$";
else if(r>96 || g >96 || r >96 )
strChar="8";
else if(r>64 || g >64 || r >64 )
strChar="X";
else if(r>32 || g >32 || r >32 )
strChar="?";
else
strChar="?";
m_edit.GetWindowText(strTemp);
strTemp=strTemp+strChar;
m_edit.SetWindowText(strTemp);
/*
if(r>224 || g >224 || r >224)
strChar="?";
else if(r>192 || g >192 || r >192 )
strChar="?";
else if(r>160 || g >160 || r >160 )
strChar="X";
else if(r>128 || g >128 || r >128 )
strChar="8";
else if(r>96 || g >96 || r >96 )
strChar="$";
else if(r>64 || g >64 || r >64 )
strChar="%";
else if(r>32 || g >32 || r >32 )
strChar="#";
else
strChar="@";
*/
}
m_edit.GetWindowText(strTemp);
strTemp=strTemp+"\r\n";
m_edit.SetWindowText(strTemp);
}
}