0

I have an Image along with labels on top of the image. My goal is to fill in the labels with information and then take a screen capture of the image with labels and save it.

I currently can take a perfect image and save it, but it does not include the labels. I tried graphics and a few other things, but am not getting anywhere.

Any help is much appreciated :)

Bitmap bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.DrawToBitmap(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
bitmap.Save("c:\\bitmap_images\\NewTest.jpeg", ImageFormat.Jpeg);
  • You shold use the same method to draw the container which contains your image and labels instead of your image. You can put all your labels and image into a panel and draw the panel. – Coskun Ozogul May 03 '17 at 14:19
  • What about writing the information with [`Graphics.DrawString()`](https://msdn.microsoft.com/en-us/library/76c5db29(v=vs.110).aspx) to the bitmap? – Jeroen van Langen May 03 '17 at 14:22
  • You can easily use DrawTpBitmap if and only if the Labels are indeed not hovering above but nested inside the Picturebox as elements of its Controls collection. To do so you need to make it their Parent in __code__! When doing so do watch their locations! Also: Use Png instead of Jpg to get legible results! – TaW May 03 '17 at 14:41

1 Answers1

0

figured it out, ty. here is code

        Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
        pictureBox1.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
        RectangleF rectf = new RectangleF(70, 90, 90, 50);

        Graphics g = Graphics.FromImage(bmp);

        g.SmoothingMode = SmoothingMode.AntiAlias;
        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
        g.PixelOffsetMode = PixelOffsetMode.HighQuality;
        g.DrawString("yourText", new Font("Tahoma", 8), Brushes.Black, rectf);

        g.Flush();

        pictureBox1.Image = bmp;
        bmp.Save("c:\\bitmap_images\\NewTest.jpeg", ImageFormat.Jpeg);