我在做打印图片时,打印出的图片不能自动缩放,我曾经想过是不是可以调整图像文件的大小,但是又确定不了调多大才适合A4纸张。请哪位老大给指点个高招啊!!顶者有分。
现用的打印代码如下:
string FileName="";
switch(tbTreat.SelectedIndex)
{
case 0:
FileName=mCurImgFile;
break;
case 1:
case 2:
FileName=mCurTreatImg;
break;
}
Image image=new Bitmap(FileName);
int x=e.MarginBounds.X;
int y=e.MarginBounds.Y;
int width=image.Width;
int height=image.Height;
if((width/e.MarginBounds.Width)>(height/e.MarginBounds.Height))
{
width=e.MarginBounds.Width;
height=image.Height*e.MarginBounds.Width/image.Width;
}
else
{
height=e.MarginBounds.Height;
width=image.Width*e.MarginBounds.Height/image.Height;
}
MessageBox.Show(width.ToString(),height.ToString());
System.Drawing.Rectangle destRect=new System.Drawing.Rectangle(x,y,width,height);
e.Graphics.DrawImage(image,destRect,0,0,image.Width,image.Height,System.Drawing.GraphicsUnit.Pixel);
现用的打印代码如下:
string FileName="";
switch(tbTreat.SelectedIndex)
{
case 0:
FileName=mCurImgFile;
break;
case 1:
case 2:
FileName=mCurTreatImg;
break;
}
Image image=new Bitmap(FileName);
int x=e.MarginBounds.X;
int y=e.MarginBounds.Y;
int width=image.Width;
int height=image.Height;
if((width/e.MarginBounds.Width)>(height/e.MarginBounds.Height))
{
width=e.MarginBounds.Width;
height=image.Height*e.MarginBounds.Width/image.Width;
}
else
{
height=e.MarginBounds.Height;
width=image.Width*e.MarginBounds.Height/image.Height;
}
MessageBox.Show(width.ToString(),height.ToString());
System.Drawing.Rectangle destRect=new System.Drawing.Rectangle(x,y,width,height);
e.Graphics.DrawImage(image,destRect,0,0,image.Width,image.Height,System.Drawing.GraphicsUnit.Pixel);
解决方案 »
- 关于Winform Tree,如何将鼠标移到文本时显示Hand,移出时还原?
- 被Thread弄得快疯了,如何安全终止线程?
- 在silverlight下dataGrid下绑定了一个combobox,如何给它赋值呢?
- 如果我有表1 ,表2,表3,表4。怎么才能用一个方法把他们都保存修改过了呢,怎么做成一个方法,该方法是返回什么类型的?
- 栈和堆的概念问题!!!
- 请教高手,我想给word窗口挂键盘钩子
- 有空过来看看,我又要骂人了
- .net MVC架构下 数据库映射的问题 急!!!
- 这段代码,大家帮我看看出了什么问题
- 我们想开发一个C#+Ms SQL Server的进销存软件,大家有兴趣,来报名!
- 问一个日期格式化的问题
- C#有没有专门写日志的类?
建议
Image image=new Bitmap(FileName);
之后,
根据要缩放的大小,再用image作为构造函数的参数
再实例一个image2
.Graphics.DrawImage(image2)