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+画的,但是保存不了,保存后是一张空白的图片,求救高手指点!