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();
}
}
}