2009-07-03 6 views
3

고해상도 .tiff 이미지를 인쇄해야하는 프로그램을 작성하고 있습니다. 내가 가지고있는 문제는 .tiff를 양질로 인쇄 할 수 없다는 것입니다. .tiff (예를 들어 8700x7200)의 크기가 크기 때문에 표준 크기의 시트에는 맞지 않습니다. DPI를 늘려 보았지만 효과가없는 것 같습니다. 내가 페이지를 맞추기 위해 .tiff를 얻을 수있는 유일한 방법은 그것을 축소하는 것입니다. 그러나 이미지는 끔찍한 품질을 가지고 있습니다. (11x17에 맞도록 크기를 조정했지만 표시되는 해상도는 1100x1700뿐입니다). 나는 프린터의 해상도 변경을 시도하고, 수동으로 그리고 프로그래밍 방식으로 프린터 품질/해상도를 설정했지만 아무런 성공도 시도하지 않았습니다. 기본적으로 11x17 페이지에 .tiff의 더 많은 픽셀을 넣을 수 있기를 원합니다. 그래서 나는 그만큼 확장 할 필요가 없습니다. 인쇄 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 리샘플링입니다.


    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