RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:9:30-18:00
你可能遇到了下面的问题
关闭右侧工具栏
给图片添加版权信息
  • 作者:zhaozj
  • 发表时间:2020-12-23 10:53
  • 来源:未知

Bitmap bitmap=new Bitmap(this.pictureBox2.Width,this.pictureBox2.Height,System.Drawing.Imaging.PixelFormat.Format24bppRgb);

//根据位图获取画布

Graphics g=Graphics.FromImage(bitmap);

//清空画布并用透明色填充

g.Clear(Color.Transparent);

//将另一幅图片画到画布上

g.DrawImage(this.pictureBox1.Image,0,0);

//写版权信息到图片上。

g.DrawString(this.textBox2.Text,new Font("黑体",15),new SolidBrush(Color.Red),new Rectangle(20,20,100,100));

//显示

this.pictureBox2.Image=bitmap;

//保存图片

bitmap.Save("c://abc.bmp",System.Drawing.Imaging.ImageFormat.Bmp);

 

       顺便帖一下“选择”按钮的单击事件程序:

private void button1_Click(object sender, System.EventArgs e)

        {

            if(this.openFileDialog1.ShowDialog()==DialogResult.OK)

            {

                if(this.openFileDialog1.FileName.Length==0)

                {

                    MessageBox.Show("请选择图片","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);

                    return;

                }

                this.textBox1.Text=this.openFileDialog1.FileName;

                FileStream fs=new FileStream(this.openFileDialog1.FileName,FileMode.Open,FileAccess.Read);

                try

                {

                    this.pictureBox1.Image=Image.FromStream(fs);

                }

                catch(Exception)

                {

                    MessageBox.Show("您选择的文件不是可识别的图片格式","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);

                }

                finally

                {

                    fs.Close();

                }

            }

        }