Gary

Gary

  • NA
  • 2
  • 0

Increasing Print Quality for images

Jul 3 2009 8:40 AM
Hi.

I'm writing a program that needs to print off high resolution .tiff images. The problem I'm having is that I can't print the .tiff's in good quality. Due to the large size of the .tiff (8700x7200 for instance) It will not fit on any standard sized sheet. I tried increasing the DPI but that didn't seem to have any effect. The only way i can get the .tiff to fit the page is too scale it down but then the image has horrendous quality. (I scale it down to fit on a 11x17, but that only has an indicated resolution of 1100x1700). i tried changing the resolutions ettings on the printer, tried manually and programatically setting the print quality/resolution but to no success. Basically I want to be able to fit more pixels of the .tiff onto the 11x17 page so I don't have to scale as much. Any help would be greatly appreciated. thanks.

The code below is what I'm attempting to do when pd.Print() is invoked.


private
void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
   try
   {
      Image tempImage = Image.FromFile(@"H:\21RR-G0K-30140-0220-0002.tiff");
      Bitmap bMap = new Bitmap(tempImage);
      bMap.SetResolution(1200, 1200);
      tempImage = bMap;
      float ImageAspectRatio = (float)tempImage.Height / (float)tempImage.Width;
      float PageSizeAspectRatio = (float)_pSize.Height / (float)_pSize.Width;
      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; //_pSize is the printing page size
         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);
         Bitmap tempMap = new Bitmap(myImage);
         tempMap.SetResolution(1200, 1200);
         RotateBicubic rotateBC = new RotateBicubic(90); //set to 90 degree rotation using bicubic interpolation
         Image finalImage = rotateBC.Apply(tempMap); //do the rotation
         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); //I realize this is the problem, but if I don't scale I can't fit the tiff on the page due to resolution differences.
         ev.Graphics.DrawImage(myImage, 0, 0);
      }
      else
      {
      } 
   }
   catch(Exception ex)
   {
      string breakpoint ="";

   }
}