Bitmap image1;//定义bitmap
private void button1_Click(object sender, EventArgs e)
{
try
{
//创建实例
image1 = new Bitmap(@"C:\Users\Administrator\Desktop\GGG\pic.jpg", true);
//写入
Graphics g = null;
g = Graphics.FromImage(image1);
Font stringFont = new Font("verdana", 20, FontStyle.Bold);
StringFormat stringFormat = new StringFormat();
stringFormat.FormatFlags = StringFormatFlags.NoWrap;
g.FillEllipse(new SolidBrush(Color.Yellow), new Rectangle(0, 0, 50, 50));
g.DrawString("测试内容", stringFont, new SolidBrush(Color.Black), new PointF(0, 0), stringFormat);
//显示
pictureBox1.Image = image1;
//保存
image1.Save(@"C:\Users\Administrator\Desktop\GGG\pic1.jpg", System.Drawing.Imaging.ImageFormat.Bmp);
}
catch (ArgumentException)
{
MessageBox.Show("There was an error." +
"Check the path to the image file.");
}
}
Bitmap创建图片、显示、保存方法示例
最新推荐文章于 2024-01-17 14:53:32 发布