打印图像时去除边框 [英] Removing borders when printing an image
本文介绍了打印图像时去除边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用标签打印机打印图像.我创建了图像,但是在打印时,在图像周围放置了大约1厘米的页面边框,这意味着我的标签一半是空的.如何禁用这些边框并将原始图像发送到打印机?
因为我的标签打印机可以像普通的Windows打印机一样工作,所以我正在使用它.我想创建一个Windows打印作业来打印图像.
I am trying to print an image using a labelprinter. I created the image but when I print it, a page border of like 1 cm is placed around the image which means half my label is empty. How can I disable these borders and sent the raw image to the printer?
As my label printer can operate as a normal windows printer I am using it like that. I want to create a windows print job to print the image.
namespace PrintSample
{
public partial class PrintForm : Form
{
private System.IO.Stream streamToPrint; string streamType;
public PrintForm()
{
InitializeComponent();
}
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt
(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code
);
private void printDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
System.Drawing.Image image = System.Drawing.Image.FromStream(this.streamToPrint);
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;
}
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);
}
public void StartPrint(Stream streamToPrint, string streamType)
{
this.printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);
this.streamToPrint = streamToPrint;
this.streamType = streamType;
System.Windows.Forms.PrintDialog PrintDialog1 = new PrintDialog();
PrintDialog1.AllowSomePages = true;
PrintDialog1.ShowHelp = true;
PrintDialog1.Document = printDoc;
DialogResult result = PrintDialog1.ShowDialog();
if (result == DialogResult.OK)
{
printDoc.Print();
}
}
private void btnPrint_Click(object sender, EventArgs e)
{
FileStream fileStream = new FileStream(@"c:\PrintPage.jpg", FileMode.Open, FileAccess.Read);
PaperSize.Equals(1, 1.5);
StartPrint(fileStream, "Image");
fileStream.Close();
}
}
}
推荐答案
此代码看起来很明智.我记得您可以通过在页边上打印来击败页边距,您是否尝试过?我还认为可以在打印对话框中设置边距.
This code looks sensible. It''s my recollection that you can defeat the margins simply by printing outside them, have you tried that ? I also thought the margins were something that can be set in the print dialog box.
这篇关于打印图像时去除边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文