windows api画柱状图 想用windows api画柱状图,且要能保存为bmp格式,那位能给帮助咯?完全不知道要怎么弄 我想达到这么个效果:画出柱状图的时候,像素点也保存在自己定义的did结构中,只需要保存为bmp 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 柱状图如果不要求画得圆润啊什么的,无非就是 fillrect 结合 rectangle #include "WINDOWSX.H" CClientDC SHDC(this);//取得客户区内存DC CPaintDC dc(this); CDC memDC; CRect rect; GetClientRect(rect); memDC.CreateCompatibleDC(&SHDC); CBitmap bm; int Width = rect.Width();// int Height = rect.Height();// bm.CreateCompatibleBitmap(&SHDC, Width, Height); CBitmap* pOld = memDC.SelectObject(&bm); memDC.BitBlt(0, 0, Width, Height, &SHDC, 0, 0, SRCCOPY); memDC.SelectObject(pOld); BITMAP btm; bm.GetBitmap(&btm); DWORD size = btm.bmWidthBytes * btm.bmHeight; LPSTR lpData =(LPSTR)GlobalAllocPtr(GPTR, size); BITMAPFILEHEADER bfh;///////////////////////////////////////////// BITMAPINFOHEADER bih; bih.biBitCount = btm.bmBitsPixel; bih.biClrImportant = 0; bih.biClrUsed = 0; bih.biCompression = 0; bih.biHeight = btm.bmHeight; bih.biPlanes = 1; bih.biSize = sizeof(BITMAPINFOHEADER); bih.biSizeImage = size; bih.biWidth = btm.bmWidth; bih.biXPelsPerMeter = 0; bih.biYPelsPerMeter = 0; GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS); bfh.bfReserved1 = bfh.bfReserved2 = 0; bfh.bfType = ((WORD)('M'<< 8)|'B'); bfh.bfSize = 54 + size; bfh.bfOffBits = 54; CFileDialog dlg(false,_T("BMP"),_T("*.bmp"),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,_T("*.bmp|*.bmp|*.*|*.*|")); if (dlg.DoModal()==IDOK) { CFile bf; CString ss=dlg.GetPathName(); if(bf.Open(ss, CFile::modeCreate | CFile::modeWrite)) { bf.WriteHuge(&bfh, sizeof(BITMAPFILEHEADER)); bf.WriteHuge(&bih, sizeof(BITMAPINFOHEADER)); bf.WriteHuge(lpData, size); bf.Close(); } GlobalFreePtr(lpData); }保存的代码,画图可以用楼上说的喊声 用画笔出来应该没问题,但是画出来之后怎么保存为bmp图片咯? http://blog.csdn.net/q1wenchang/article/details/5824769 @heksnheksn应该理解错我的意思了,我是想画柱状图(柱状图要在程序中通过数据统计得到),用画笔话,这个链接中的保存对我有用,却没有讲如何获取画笔画的图 存BMP没研究过,不过画柱状图有个简单的笨方法,就是把平面叠加起来画。 @shn521谢谢啦,我还没看您3楼的代码 哈哈,在研究读取,彩色图和灰度图不知道怎么分别读取和显示 VC中的ActiveX的Flash插件可以播放在线MP3吗? 登陆模块 直接在button按钮中验证用户名密码和用sql验证的区别 CCOMBOBOX控件如何实现 动态生成的菜单项,怎么响应菜单里的点击事件 CSerialPort 问题,100分, 关于sendmessge 如何钩内存? 如何使Static控件的宽,自动的与对话框宽度相同? 急!关于数据类型转换的问题 z怎样用汇编把网管废掉?? 无奈ing~~~~~~~~,IDE自动退出的问题。。。。 双重指针内存释放问题 vc树控件OnSelchangedTree中的问题!
CPaintDC dc(this);
CDC memDC;
CRect rect;
GetClientRect(rect); memDC.CreateCompatibleDC(&SHDC);
CBitmap bm;
int Width = rect.Width();//
int Height = rect.Height();//
bm.CreateCompatibleBitmap(&SHDC, Width, Height);
CBitmap* pOld = memDC.SelectObject(&bm);
memDC.BitBlt(0, 0, Width, Height, &SHDC, 0, 0, SRCCOPY);
memDC.SelectObject(pOld);
BITMAP btm;
bm.GetBitmap(&btm);
DWORD size = btm.bmWidthBytes * btm.bmHeight;
LPSTR lpData =(LPSTR)GlobalAllocPtr(GPTR, size);
BITMAPFILEHEADER bfh;
/////////////////////////////////////////////
BITMAPINFOHEADER bih;
bih.biBitCount = btm.bmBitsPixel;
bih.biClrImportant = 0;
bih.biClrUsed = 0;
bih.biCompression = 0;
bih.biHeight = btm.bmHeight;
bih.biPlanes = 1;
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biSizeImage = size;
bih.biWidth = btm.bmWidth;
bih.biXPelsPerMeter = 0;
bih.biYPelsPerMeter = 0;
GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);
bfh.bfReserved1 = bfh.bfReserved2 = 0;
bfh.bfType = ((WORD)('M'<< 8)|'B');
bfh.bfSize = 54 + size;
bfh.bfOffBits = 54; CFileDialog dlg(false,_T("BMP"),_T("*.bmp"),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,_T("*.bmp|*.bmp|*.*|*.*|"));
if (dlg.DoModal()==IDOK)
{
CFile bf;
CString ss=dlg.GetPathName();
if(bf.Open(ss, CFile::modeCreate | CFile::modeWrite))
{
bf.WriteHuge(&bfh, sizeof(BITMAPFILEHEADER));
bf.WriteHuge(&bih, sizeof(BITMAPINFOHEADER));
bf.WriteHuge(lpData, size);
bf.Close();
}
GlobalFreePtr(lpData);
}
保存的代码,画图可以用楼上说的喊声
heksn应该理解错我的意思了,我是想画柱状图(柱状图要在程序中通过数据统计得到),用画笔话,这个链接中的保存对我有用,却没有讲如何获取画笔画的图