想用windows api画柱状图,且要能保存为bmp格式,那位能给帮助咯?
完全不知道要怎么弄 
我想达到这么个效果:画出柱状图的时候,像素点也保存在自己定义的did结构中,只需要保存为bmp

解决方案 »

  1.   

    柱状图如果不要求画得圆润啊什么的,无非就是 fillrect 结合 rectangle
      

  2.   

    #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);
     }
    保存的代码,画图可以用楼上说的喊声
      

  3.   

    用画笔出来应该没问题,但是画出来之后怎么保存为bmp图片咯?
      

  4.   

    http://blog.csdn.net/q1wenchang/article/details/5824769
      

  5.   

    @heksn
    heksn应该理解错我的意思了,我是想画柱状图(柱状图要在程序中通过数据统计得到),用画笔话,这个链接中的保存对我有用,却没有讲如何获取画笔画的图
      

  6.   

    存BMP没研究过,不过画柱状图有个简单的笨方法,就是把平面叠加起来画。
      

  7.   

    @shn521谢谢啦,我还没看您3楼的代码 哈哈,在研究读取,彩色图和灰度图不知道怎么分别读取和显示