Screenshot quality is worse than usual

I am trying to capture a portion of my screen. The problem is that even if I use png to save the image, the quality is even worse than if I were using a regular print screen. In the meantime, there is no need to know about it. ”

Here is the code I'm using:

        //display a save file dialog for the user to set the file name
        SaveFileDialog saveFileDialog = new SaveFileDialog();

        saveFileDialog.Filter = "PNG (*.png)|*.png";
        saveFileDialog.FilterIndex = 0;
        saveFileDialog.RestoreDirectory = true;

        //if the user proceed saving the picture
        if (saveFileDialog.ShowDialog() == DialogResult.OK)
        {
            //simplify code with constant numbers for demo

            //get the width of the panel we need the screenshoot off
            int x = 10;
            //get the height of the panel we need the screenshoot off
            int y = 10;
            //create the ractangle of the screenshoot panel
            Rectangle rect = new Rectangle(x, y, 5, 5);
            //create new bitmap
            Bitmap bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);
            Graphics g = Graphics.FromImage(bmp);

            //get the screenshoot of the panel
            g.CopyFromScreen(rect.Left, rect.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy);

            string fileName = saveFileDialog.FileName;
            if (!fileName.Contains(".png"))
                fileName += ".png";

            bmp.Save(fileName, ImageFormat.Png);
        }

      

EDIT:

An example of an image form I'm using with code: enter image description here

Normal screenshot:

enter image description here

There isn't much here, but it's worse.

+3


source to share


3 answers


The top image in your question has been modified, smaller than the original. This is noticeable in images containing fine details, such as ClearType anti-aliasing pixels, used to make text easier to read. When they get rescaled, the visual effect is destroyed and the text looks much worse.



It is not clear why the image was rescaled, nothing in the code could cause this. Double check using the debugger to check the bmp.HorizontalResolution property, it should match the DPI of your video adapter. The simplest explanation that this was done with whatever image viewer you were using, perhaps the image to fit the window. Try scaling.

+4


source


If an external library can be used, I suggest you FMUtils.Screenshot . It is available as a NuGet package.

I just tried it and the quality is similar to a standard screen shot from windows. Here's a quick example:



new ComposedScreenshot(new Rectangle(0, 0, 100, 100)).ComposedScreenshotImage.Save(@"PATH_TO_FILE\example-screenshot.png", ImageFormat.Png);

      

Hope this helps!

0


source


The pixel format used uses only 8 bits for the different color channels. You can try using PixelFormat64bppARGB to get 16 bits per color.

Resource for PixelFormat enumeration: http://msdn.microsoft.com/en-us/library/system.drawing.imaging.pixelformat%28v=vs.110%29.aspx

-1


source







All Articles