0

I have been using Bitmap to take a capture of my main form and saving it as jpeg. Unfortunately bitmap does not keep my text colour. Best way I can describe this is by images (see below). My mainform has an objectlistview which has a column coloured red. Bitmap however captures this as black text? why?

Is there any other alternative method I can use?

I have tried capturing screen and cutting out the the mainform as shown in the code below. This works great on a 1080p monitor, but not on my 4k monitor with 200% scaling, it results in the image being cut.

public void SaveControlImage(Form form)
        {
            string path_and_file = "C:\1.png";
            Bitmap controlBitMap = new Bitmap(form.Width, form.Height);
            Graphics g = Graphics.FromImage(controlBitMap);
            g.CopyFromScreen(PointToScreen(form.Location), new Point(0, 0), form.Size);

            // example of saving to the desktop
            controlBitMap.Save(path_and_file, System.Drawing.Imaging.ImageFormat.Png);
        }

How main form looks

what bitmap capture shows

jason.kaisersmith
  • 8,712
  • 3
  • 29
  • 51
Breakwin
  • 84
  • 6
  • Not sure what is your problem, but there is another approach to obtain screenshots, check [this answer](https://stackoverflow.com/a/24478299/1997232). – Sinatr Mar 05 '21 at 14:37
  • Try [this class](https://stackoverflow.com/a/57257205/7444103), it should handle High-Dpi, provided that your app is DpiAware. See the notes there and [here](https://stackoverflow.com/a/53026765/7444103). – Jimi Mar 05 '21 at 14:50
  • @Jimi I tried this class. Unfortunately no matter what I pass in it seems like its printing a blank form. No labels, panels, groupboxes are being drawn. Any suggestions? – Breakwin Mar 08 '21 at 10:48
  • So, if you call `var bitmap = ControlPrinter.ScrollableControlToBitmap(this, true, true);` from the Form you want to print, you get back a *blank Image*? That's not possible. Show what code you're using and when/where/how you're calling it. – Jimi Mar 08 '21 at 10:58
  • @Jimi I made a new .cs with the class and that builds fine. this is in my main form `var bitmap = ControlPrinter.ScrollableControlToBitmap(this, true, true); bitmap.Save(path_and_file, System.Drawing.Imaging.ImageFormat.Png);` What ends up showing is this: [![image][1]][1] I have also tried passing in panels and other types of controls and none of them unfortunately yield in any difference. [1]: https://i.stack.imgur.com/wrJRR.png – Breakwin Mar 08 '21 at 11:59
  • Right. Build a new Form, add some random controls to it. Also, add two Buttons and two PictureBoxes. Set the PictureBoxes `.SizeMode = Zoom`. In the first Button.Click handler, add: `pictureBox1.Image = ControlPrinter.ScrollableControlToBitmap(this, true, true);`, in the other Button, `var bitmap = new Bitmap(this.Width, this.Height); this.DrawToBitmap(bitmap, this.Bounds); pictureBox2.Image = bitmap;`. See what you get in the IDE. – Jimi Mar 08 '21 at 12:08
  • @Jimi button1 does not do anything to picturebox1 button2 creates some sort of cropped image of of the form in picturebox 2 https://i.imgur.com/1S5p1XE.png Is this expected? It is built with .net core 5.0 – Breakwin Mar 08 '21 at 16:17
  • @Jimi tried again with net framework 4.8. Same result, calling controlprinter does not yield in any results. Bitmap works... but has its issues – Breakwin Mar 08 '21 at 16:23

0 Answers0