大家好,请教大家,我想保存picturebox上的图像,图像上其实有label控件编辑的文字,但是怎么也显示不了上面的文字,怎么办,请教大家指点,谢谢

解决方案 »

  1.   

    我就是简单的在form中加入一个picturebox1控件,控件中加入一个图片,后来又加一个label1控件,文字能够显示在picturebox上,但是保存,却保存不到一起,我的程序大概这样的,
    private void Form1_Load(object sender, EventArgs e)
            {
               
                pictureBox1.Controls.Add(label1);
             
                pictureBox1.Controls.Add(label9);
                label1.BackColor = Color.Transparent;//透明底色 
                label1.Location = new Point(885, 100);
                label1.AutoSize = true;
            }     点击button 进行保存
          private void button1_Click(object sender, EventArgs e)
            {
                bool isSave = true;
                SaveFileDialog saveImageDialog = new SaveFileDialog();
                saveImageDialog.Title = "图片保存";
                saveImageDialog.Filter = @"jpeg|*.jpg|bmp|*.bmp|gif|*.gif";
                if (saveImageDialog.ShowDialog() == DialogResult.OK)
                {
                    string fileName = saveImageDialog.FileName.ToString();                if (fileName != "" && fileName != null)
                    {
                        string fileExtName = fileName.Substring(fileName.LastIndexOf(".") + 1).ToString();                    System.Drawing.Imaging.ImageFormat imgformat = null;                    if (fileExtName != "")
                        {
                            switch (fileExtName)
                            {
                                case "jpg":
                                    imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;
                                    break;
                                case "bmp":
                                    imgformat = System.Drawing.Imaging.ImageFormat.Bmp;
                                    break;
                                case "gif":
                                    imgformat = System.Drawing.Imaging.ImageFormat.Gif;
                                    break;
                                default:
                                    MessageBox.Show("只能存取为: jpg,bmp,gif 格式");
                                    isSave = false;
                                    break;
                            }
                            //默认保存为JPG格式   
                            if (imgformat == null)
                            {
                                imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;
                            }                        if (isSave)
                            {
                                try
                                {
                                   
                                       
                                    Bitmap bit = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                                    Graphics g = Graphics.FromImage(bit);//从指定的 Image 创建新的 Graphics(绘图)。
                                    g.DrawImage(pictureBox1.Image, new Rectangle(0, 0, bit.Width, bit.Height), new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height), GraphicsUnit.Pixel);
                                   
                                    
                                    
                                   pictureBox1.Image.Save(fileName, imgformat);
                                    MessageBox.Show("图片已经成功保存!");   
                                }
                                catch
                                {
                                    MessageBox.Show("保存失败,你还没有截取过图片或已经清空图片!");
                                }
                            }   
                        
                        }
                    }
                }
            }
      

  2.   

    直接上图片上写字,不要通过label实现。
     Graphics g = Graphics.FromImage(pictureBox1.Image);
                Pen pen=new Pen(Color.Crimson);
                Brush brush=new SolidBrush(Color.Cyan);
                Font drawFont = new Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Millimeter);
                g.DrawString("求分求鼓励", drawFont, brush, 0, 0);
                pictureBox1.Image.Save(@"C:\Users\ll\Desktop\1.jpg");
      

  3.   

    或者可以调用API 函数 截屏保存图片
      

  4.   


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

  5.   

    你Label只是在Picturebox控件上而已,不代表在图片上有这个东西啊,你如果要保证图片有你写的东西,你应该使用GDI来把字符串画到这张图片的指定位置了,具体第六楼的代码的