PictureBOX图片保存,添加文字

private void btnSave_Click(object sender, EventArgs e)
        {
            Image img = (Image)pictureBox1.Image.Clone();
            using (Brush brush = new SolidBrush(label1.ForeColor))
            using (Graphics g = Graphics.FromImage(img))
            {
                Rectangle rect = new Rectangle(label1.Left - pictureBox1.Left, label1.Top- pictureBox1.Top, label1.Width, label1.Height);
                if (label1.BackColor != Color.Transparent)
                {
                    using (Brush bgBrush = new SolidBrush(label1.BackColor))
                    {
                        g.FillRectangle(bgBrush, rect);
                    }
                }
                g.DrawString(label1.Text, label1.Font, brush, rect, StringFormat.GenericDefault);
                g.Save();
            }
            img.Save("d:\\abc.png", System.Drawing.Imaging.ImageFormat.Png);
        }


你可能感兴趣的:(PictureBOX图片保存,添加文字)