打印图像 c#.net [英] Print images c#.net

查看:37
本文介绍了打印图像 c#.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 PictureBox 中有一个图像,我想打印它.无格式,无任何内容,只需打印即可.

I have an image in a PictureBox, and I want to print it. No formatting, no nothing, just print it.

我一直在 Google 上搜索,但一无所获,只有打印表格、文本或报告的人.

I've been searching on Google but I've got nothing, only people printing forms or text or reports.

private string imgSrc;

    public string ImgSrc
    {
        get { return imgSrc; }
        set { imgSrc = value; }
    }

    public Id_Manager()
    {
        ImgSrc = "D:\Foto.jpg";

        InitializeComponent();
        idPicture.Load(this.ImgSrc);
    }

显然图像会发生变化,但现在我只对打印该图像感兴趣.我将 url 保存在一个属性中以防万一.有什么帮助吗?

Obviously the image is going to change, but for now I'm just interested in printing that image. I'm saving the url in a property just in case. Any help?

推荐答案

下面的代码使用 PrintDocument 对象,您可以将图像放在打印文档上然后打印.

The Code below uses the PrintDocument object which you can place an image on to the printdocument and then print it.

using System.Drawing.Printing;
...
protected void btnPrint_Click(object sender, EventArgs e)
{
    PrintDocument pd = new PrintDocument();
    pd.PrintPage += PrintPage;
    pd.Print();       
}

private void PrintPage(object o, PrintPageEventArgs e)
{
    System.Drawing.Image img = System.Drawing.Image.FromFile("D:\Foto.jpg");
    Point loc = new Point(100, 100);
    e.Graphics.DrawImage(img, loc);     
}

这篇关于打印图像 c#.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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