打印图像与PrintDocument的。如何调整图像以适合纸张大小 [英] Printing image with PrintDocument. how to adjust the image to fit paper size

查看:3860
本文介绍了打印图像与PrintDocument的。如何调整图像以适合纸张大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,我尝试使用PrintDocument类与下面code打印图像。图像尺寸是1200像素宽和1800像素的高度。我尝试打印使用小ZEEBRA打印机在4 * 6纸这一形象。但该方案仅打印4 * 6的大形象。这意味着它不会在图像调整纸张大小!

In C#, I am trying to print an image using PrintDocument class with the below code. The image is of size 1200 px width and 1800 px height. I am trying to print this image in a 4*6 paper using a small zeebra printer. But the program is printing only 4*6 are of the big image. that means it is not adjusting the image to the paper size !

     PrintDocument pd = new PrintDocument();
     pd.PrintPage += (sender, args) =>
     {
           Image i = Image.FromFile("C://tesimage.PNG");
           Point p = new Point(100, 100);
           args.Graphics.DrawImage(i, 10, 10, i.Width, i.Height);
     };
     pd.Print();

当我使用窗口打印打印相同的图像(点击右键并选择打印,它会自动缩放到纸张大小和打印正确。这意味着一切都排在4 * 6纸。)我如何做同样的在我的C#计划?

When i print the same image using Window Print (right click and select print, it is scaling automatically to paper size and printing correctly. that means everything came in 4*6 paper.) How do i do the same in my C# program ?

推荐答案

要传递到drawImage方法的参数应该是你想要纸上的图像,而不是图像本身的尺寸大小,的DrawImage命令那么会照顾缩放的为您服务。也许最简单的方法是使用的DrawImage命令的以下重写。

The parameters that you are passing into the DrawImage method should be the size you want the image on the paper rather than the size of the image itself, the DrawImage command will then take care of the scaling for you. Probably the easiest way is to use the following override of the DrawImage command.

args.Graphics.DrawImage(i, args.MarginBounds);

注意:这将歪斜的图像,如果图像的比例是不一样的矩形。在图像和纸张尺寸的大小一些简单的数学将允许你创建的文件的界限不适合的倾斜图像的新矩形。

Note: This will skew the image if the proportions of the image are not the same as the rectangle. Some simple math on the size of the image and paper size will allow you to create a new rectangle that fits in the bounds of the paper without skewing the image.

这篇关于打印图像与PrintDocument的。如何调整图像以适合纸张大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆