Improving image print quality

I am writing a program that should print high resolution .tiff images. The problem I am facing is that I cannot print .tiff in good quality. Due to the large .tiff size (e.g. 8700x7200), it does not fit on any standard sheet. I tried increasing the DPI, but it showed no effect. The only way I can get .tiff to fit the page is to zoom out. but then the image has terrifying quality. (I scale it to fit 11x17, but this only has the specified resolution of 1100x1700). I tried to change the print permissions on the printer, tried to manually and programmatically set the quality / resolution of the printer, but to no avail. Basically, I want to allow for more .tiff pixels on the 11x17 page,so I don’t need to scale that much. I thought that increasing the DPI for printing would increase the number of pixels by 11x17 inches, but that didn't affect me. Maybe I'm doing something wrong. Any help would be greatly appreciated. thanks.

Below is the code I'm trying to do right now when pd.Print () is called.

    private void pd_PrintPage(object sender, PrintPageEventArgs ev)
    {
        //float x = ev.MarginBounds.Left;
        //float y = ev.MarginBounds.Top;
        try
        {
            //ResizeImage(@"H:\21RR-G0K-30140-0220-0002.tiff", @"H:\21RR-G0K-30140-0220-0002-new.tiff", 500, 900, false);
            Image tempImage = Image.FromFile(@"H:\21RR-G0K-30140-0220-0002.tiff");
            Bitmap bMap = new Bitmap(tempImage);
            bMap.SetResolution(1200, 1200);
            string l = "";
            tempImage = bMap;
            /*if (tempImage.Width > tempImage.Height)  //if poster is longer then it is tall, rotate the image. Done to match standard printing aspect ratios
            {
                Bitmap tempBitmap = new Bitmap(tempImage); //Need to convert to Bitmap type to do rotation
                RotateBicubic rotationFilter = new RotateBicubic(90, true);
                tempImage = rotationFilter.Apply(tempBitmap);
            }*/
            float ImageAspectRatio = (float)tempImage.Height / (float)tempImage.Width;  
            float PageSizeAspectRatio = (float)_pSize.Height / (float)_pSize.Width; //_pSize is the selected printing sheet size
            if (ImageAspectRatio < 1 && PageSizeAspectRatio > 1) //Need to rotate Image. Can't attempt to rotate tempImage due to size. Scale then rotate.
            {
                double x_scale = (double)_pSize.Width / (double)tempImage.Height;
                double y_scale = (double)_pSize.Height / (double)tempImage.Width;
                int percent = 0;
                if (y_scale < x_scale)
                {
                    percent = Convert.ToInt32(y_scale * 100);
                }
                else
                {
                    percent = Convert.ToInt32(x_scale * 100);
                }
                Image myImage = ImageManipulation.ScaleByPercent(tempImage, percent); //I know this line is the problem, but I can't fit the image on the page without massive scaling due to the page reolution restraints
                Bitmap tempMap = new Bitmap(myImage);
                tempMap.SetResolution(1200, 1200);
                RotateBicubic rotateBC = new RotateBicubic(90);
                Image finalImage = rotateBC.Apply(tempMap); //rotate the image 90 degrees using bicubic interpolation. This isn't what killing the quality as the quality is no better with this disabled
                ev.Graphics.DrawImage(finalImage, 0, 0);
            }
            else if (ImageAspectRatio >= 1 && PageSizeAspectRatio >= 1) //No Need for rotation 
            {
                double x_scale = (double)_pSize.Width / (double)tempImage.Width;
                double y_scale = (double)_pSize.Height / (double)tempImage.Height;
                int percent = 0;
                if (y_scale < x_scale)
                {
                    percent = Convert.ToInt32(y_scale * 100);
                }
                else
                {
                    percent = Convert.ToInt32(x_scale * 100);
                }

                Image myImage = ImageManipulation.ScaleByPercent(tempImage, percent);
                ev.Graphics.DrawImage(myImage, 0, 0);

            }

            else
            {

            }              
        }
        catch(Exception ex)
        {
            string breakingpoint = "";
        }
    }
+3
source share
2 answers

The term you are looking for is "resampling."

It is also best to scale the image using the device coordinate system or the GDI + HIENGLISH blocks (I believe this is used in the context of the printing device.)

Using the DrawImage command, the best you are going to get from GDI + is HighQualityBicubic Resampling.


    Private Sub pd_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pd.PrintPage

        Dim img As Image = Image.FromFile("SAMPLE.TIF")

        Dim imageWidth As Integer = CInt((img.Width / img.HorizontalResolution) * 100)
        Dim imageHeight As Integer = CInt((img.Height / img.VerticalResolution) * 100)

        If imageWidth > e.PageBounds.Width Then
            Dim ratio As Double = imageWidth / imageHeight
            imageWidth = e.PageBounds.Width
            If ratio < 1 Then
                imageHeight = CInt(imageWidth * ratio)
            Else
                imageHeight = CInt(imageWidth / ratio)
            End If
        End If

        If imageHeight > e.PageBounds.Height Then
            Dim ratio As Double = imageHeight / imageWidth
            imageHeight = e.PageBounds.Height
            If ratio < 1 Then
                imageWidth = CInt(imageHeight * ratio)
            Else
                imageWidth = CInt(imageHeight / ratio)
            End If
        End If

        e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
        e.Graphics.DrawImage(img, 0, 0, imageWidth, imageHeight)

    End Sub

+3
source

It seems that the problem is with the scaling procedure. You might want to explore some third-party libraries that include high-quality scaling algorithms.

+1
source

Source: https://habr.com/ru/post/1711812/


All Articles