| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 700 人关注过本帖
标题:GDI+ 一般项错误
取消只看楼主 加入收藏
cmgm
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-2-27
结帖率:0
收藏
 问题点数:0 回复次数:4 
GDI+ 一般项错误
这是我的button事件的代码   ,运行之后,在*** 这行报错(截图如下),提示“GDI+ 一般项错误”,drawPic()方法没错,但是就是找不到在指定路径下的jpg文件
,个人感觉还是路径的问题,哪位高手给解决一下???
private void button1_Click(object sender, EventArgs e)
        {
            this.Enabled = false;
            this.Enabled = true;
            Graphics objgraphics = this.CreateGraphics();
            string P_str_imagePath = Application.StartupPath.Substring(0,Application.StartupPath.Substring(0,Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));
            P_str_imagePath += @"\Image\image\" + DateTime.Now.ToString("yyyyMMddhhmss") + ".jpg";
            try
            {

                dbo.drawPic(objgraphics, "select name,num from tb_countryFourBT ", "tb_countryFourBT", "num", "name", "黔江区贫困指标贡献度统计");
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
             ***   System.Drawing.Image myImage = Image.FromFile(P_str_imagePath);
                picbox.Image = myImage;

            }
        }
搜索更多相关主题的帖子: false private button 
2013-04-11 10:17
cmgm
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-2-27
收藏
得分:0 
怎样改合适 ??现在根本就找不到Image\image 路径   文件夹根本就没生成
2013-04-11 11:20
cmgm
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-2-27
收藏
得分:0 
你看看
2013-04-11 12:07
cmgm
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-2-27
收藏
得分:0 
public void drawPic(Graphics objgraphics, string M_str_sqlstr, string M_str_table, string M_str_Num, string M_str_tbGName, string M_str_title)
        {
            DataSet myds = this.getds(M_str_sqlstr, M_str_table);
            float M_flt_total = 0.0f, M_flt_tmp;
            int M_int_iloop;
            for (M_int_iloop = 0; M_int_iloop < myds.Tables[0].Rows.Count; M_int_iloop++)
            {
                M_flt_tmp = Convert.ToSingle(myds.Tables[0].Rows[M_int_iloop][M_str_Num]);
                M_flt_total += M_flt_tmp;
            }
            Font fontlegend = new Font("verdana", 9), fonttitle = new Font("verdana", 10, FontStyle.Bold);//设置字体
            int M_int_width = 275;//白色背景宽
            const int Mc_int_bufferspace = 15;
            int M_int_legendheight = fontlegend.Height * (myds.Tables[0].Rows.Count + 1) + Mc_int_bufferspace;
            int M_int_titleheight = fonttitle.Height + Mc_int_bufferspace;
            int M_int_height = M_int_width + M_int_legendheight + M_int_titleheight + Mc_int_bufferspace;//白色背景高
            int M_int_pieheight = M_int_width;
            Rectangle pierect = new Rectangle(0, M_int_titleheight, M_int_width, M_int_pieheight);
            //加上各种随机色
            Bitmap objbitmap = new Bitmap(M_int_width, M_int_height);//创建一个bitmap实例
            objgraphics = Graphics.FromImage(objbitmap);
            ArrayList colors = new ArrayList();
            Random rnd = new Random();
            for (M_int_iloop = 0; M_int_iloop < myds.Tables[0].Rows.Count; M_int_iloop++)
                colors.Add(new SolidBrush(Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255))));
            objgraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, M_int_width, M_int_height);//画一个白色背景
            objgraphics.FillRectangle(new SolidBrush(Color.LightYellow), pierect);//画一个亮黄色背景
            //以下为画饼图(有几行row画几个)
            float M_flt_currentdegree = 0.0f;
            for (M_int_iloop = 0; M_int_iloop < myds.Tables[0].Rows.Count; M_int_iloop++)
            {
                objgraphics.FillPie((SolidBrush)colors[M_int_iloop], pierect, M_flt_currentdegree,
                  Convert.ToSingle(myds.Tables[0].Rows[M_int_iloop][M_str_Num]) / M_flt_total * 360);
                M_flt_currentdegree += Convert.ToSingle(myds.Tables[0].Rows[M_int_iloop][M_str_Num]) / M_flt_total * 360;
            }
            //以下为生成主标题
            SolidBrush blackbrush = new SolidBrush(Color.Black);
            StringFormat stringFormat = new StringFormat();
            stringFormat.Alignment = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Center;
            objgraphics.DrawString(M_str_title, fonttitle, blackbrush, new Rectangle(0, 0, M_int_width, M_int_titleheight), stringFormat);
            objgraphics.DrawRectangle(new Pen(Color.Black, 2), 0, M_int_height - M_int_legendheight, M_int_width, M_int_legendheight);
            for (M_int_iloop = 0; M_int_iloop < myds.Tables[0].Rows.Count; M_int_iloop++)
            {
                objgraphics.FillRectangle((SolidBrush)colors[M_int_iloop], 5, M_int_height - M_int_legendheight + fontlegend.Height * M_int_iloop + 5, 10, 10);
                objgraphics.DrawString(((String)myds.Tables[0].Rows[M_int_iloop][M_str_tbGName]) + " —— "
                    + Convert.ToString(Convert.ToSingle(myds.Tables[0].Rows[M_int_iloop][M_str_Num]) * 100 / M_flt_total) + "%", fontlegend, blackbrush,
                20, M_int_height - M_int_legendheight + fontlegend.Height * M_int_iloop + 1);
            }
            //objgraphics.DrawString("总数是:" + Convert.ToString(M_flt_total), fontlegend, blackbrush, 5, M_int_height - fontlegend.Height);
            string P_str_imagePath = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0,
                Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));
            P_str_imagePath += @"\Image\image\" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";
            objbitmap.Save(P_str_imagePath, ImageFormat.Jpeg);
            objgraphics.Dispose();
            objbitmap.Dispose();
        }
2013-04-11 12:38
cmgm
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-2-27
收藏
得分:0 
回复 8楼 yhlvht
谢谢版主   解决了
2013-04-11 16:34
快速回复:GDI+ 一般项错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016477 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved