Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to save viewport as bitmap? #47

Open
johmarjac opened this issue Feb 21, 2022 · 1 comment
Open

How to save viewport as bitmap? #47

johmarjac opened this issue Feb 21, 2022 · 1 comment

Comments

@johmarjac
Copy link

johmarjac commented Feb 21, 2022

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.

@cyotek
Copy link
Owner

cyotek commented Feb 23, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants