Cyotek.Windows.Forms.ImageBox icon indicating copy to clipboard operation
Cyotek.Windows.Forms.ImageBox copied to clipboard

How to save viewport as bitmap?

Open johmarjac opened this issue 3 years ago • 1 comments

Hi, i am overriding OnPaint and draw an overlay on my image.

Can I Somehow save that whole construct of Image + Overlay in a .BMP file? When I use DrawToBitmap it renders only the visible part, but i want the whole part.

johmarjac avatar Feb 21 '22 11:02 johmarjac

Hello,

I probably wouldn't do this from OnPaint as this event can be frequently called and could slow your application down if you put expensive code in it.

You could probably use something similar to the following to create a copy of the source image, apply your custom overlay, and then save it to a file.

      using (Bitmap copy = new Bitmap(imageBox.Image))
      {
        using (Graphics graphics = Graphics.FromImage(copy))
        {
          // draw overlay
        }

        copy.Save(@"t:\temp\copy.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
      }

Hopefully this gives you a starting point!

Regards; Richard Moss

cyotek avatar Feb 23 '22 08:02 cyotek