| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 792 人关注过本帖
标题:c# 中怎样把 在 PictureBox 中画好的图形保存为图片文件(如 jpg,bmp,gif)
取消只看楼主 加入收藏
daren_zj
Rank: 1
等 级:新手上路
帖 子:3
专家分:8
注 册:2013-4-8
结帖率:0
收藏
已结贴  问题点数:20 回复次数:0 
c# 中怎样把 在 PictureBox 中画好的图形保存为图片文件(如 jpg,bmp,gif)
private void button1_Click(object sender, EventArgs e)
        {
            int tem_Line = 0;
            int circularity_W = 4;
            if (pictureBox1.Width >= pictureBox1.Height)
                tem_Line = pictureBox1.Height;
            else
                tem_Line = pictureBox1.Width;
            //
            Rectangle rect = new Rectangle(circularity_W, circularity_W, tem_Line - circularity_W * 2, tem_Line - circularity_W * 2);
            Font star_Font = new Font("Arial", 30, FontStyle.Regular);
            string star_Str = "★";
            Graphics g = this.pictureBox1.CreateGraphics();
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.Clear(Color.White);
            Pen myPen = new Pen(Color.Red, circularity_W);
            g.DrawEllipse(myPen, rect);
            SizeF Var_Size = new SizeF(rect.Width, rect.Width);
            Var_Size = g.MeasureString(star_Str, star_Font);
            g.DrawString(star_Str,star_Font,myPen.Brush,new PointF((rect.Width / 2F+circularity_W-Var_Size.Width/2F),(rect.Height / 2F -Var_Size.Width / 2F)));
            Font Var_Font = new Font("楷体", 20, FontStyle.Regular);
            
            Var_Size = g.MeasureString("专用章", Var_Font);
            g.DrawString("专用章", Var_Font, myPen.Brush, new PointF((rect.Width / 2F) + circularity_W - Var_Size.Width / 2F, rect.Height / 2F + Var_Size.Height * 2));
            string tempStr = "四川省万源市金属回收公司";
            int len = tempStr.Length;
            float angle = 180 + (180 - len * 20) / 2;
            for (int i = 0; i < len; i++)
            {
                g.TranslateTransform((tem_Line + circularity_W / 2) / 2, (tem_Line + circularity_W / 2) / 2);
                g.RotateTransform(angle);
                Brush myBrush = Brushes.Red;
                g.DrawString(tempStr.Substring(i, 1), Var_Font, myBrush, 60, 0);
                g.ResetTransform();
                angle += 20;
            }
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem == null)
            {
                return;
            }
            else
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Title = "保存为:";
                saveFileDialog.OverwritePrompt = true;
                saveFileDialog.CheckPathExists = true;
                saveFileDialog.Filter = comboBox1.Text + "|" + comboBox1.Text;
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    string fileName = saveFileDialog.FileName;
                    Bitmap bitmap = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);
                    bitmap.Save(fileName, ImageFormat.Jpeg);
                }
            }
        }


我刚开始学习C#,c#中怎样把 在PictureBox中画好的图形保存为图片文件(如jpg,bmp,gif),我是用GDI+画的,但是保存不了,保存后是一张空白的图片,求救高手指点!
搜索更多相关主题的帖子: private 图片 
2014-07-15 18:14
快速回复:c# 中怎样把 在 PictureBox 中画好的图形保存为图片文件(如 jpg,bmp,g ...
数据加载中...
 
   



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

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