我在寫一個需要打印高分辨率.tiff圖像的程序。我遇到的問題是我無法打印質量很好的.tiff文件。由於.tiff的大尺寸(例如8700x7200),它不適合任何標準尺寸的紙張。我試圖增加新聞部,但似乎沒有任何影響。我可以讓.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 = "";
}
}
任何你推薦的?現在我正在使用AForge圖像庫 – Megatron 2009-07-03 17:48:10