2009-07-03 2 views
3

Я пишу программу, которая должна печатать изображения с высоким разрешением .tiff. Проблема, с которой я сталкиваюсь, заключается в том, что я не могу напечатать .tiff в хорошем качестве. Из-за большого размера .tiff (например, 8700x7200) Он не подходит ни на одном стандартном листе. Я попытался увеличить DPI, но это не показало никакого эффекта. Единственный способ, которым я могу получить .tiff, чтобы соответствовать странице, - это уменьшить масштаб. но тогда изображение имеет ужасающее качество. (Я масштабирую его, чтобы соответствовать 11x17, но это имеет только указанное разрешение 1100x1700). я попытался изменить разрешения на печать на принтере, попробовал вручную и программно установить качество/разрешение принтера, но безуспешно. В принципе, я хочу, чтобы учесть больше пикселей .tiff на странице 11x17, поэтому мне не нужно масштабировать столько. Я думал, что увеличение dpi для печати увеличит количество пикселей на 11x17 дюймов, но это не повлияло на меня. Может быть, я делаю что-то неправильно. Любая помощь будет принята с благодарностью. Благодарю.Повышение качества печати изображений

Код, приведенный ниже, является тем, что я пытаюсь сделать прямо сейчас, когда вызывается pd.Print().

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's 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

Термин, который вы ищете, это «передискретизация».

Это также, вероятно, лучше, чтобы масштабировать изображение с помощью устройства системы или GDI + HIENGLISH единиц (я считаю, что это то, что используется в контексте печатающего устройства.)

Использование DrawImage команды лучшее, что вы собираетесь координировать получить от GDI + является 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 

1

Похоже, что проблема заключается в процедуре масштабирования. Возможно, вам стоит изучить некоторые сторонние библиотеки, которые включают высококачественные алгоритмы масштабирования.

+0

Любые вы рекомендуете? сейчас я использую библиотеку AForge Imaging – Megatron

Смежные вопросы