我要从数据库中打印图片,我要在图片框中显示图片,而不要打印包含图片框 [英] i want print picture from database i show picture in picturebox than print contain picturebox

查看:65
本文介绍了我要从数据库中打印图片,我要在图片框中显示图片,而不要打印包含图片框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是

my code is

DataSet ds = new DataSet();
string strsql = "select * from clue where  id=" + Convert.ToInt32(textBox1.Text);
SqlConnection con = new SqlConnection(strcon);
con.Open();

SqlDataAdapter strada = new SqlDataAdapter(strsql, con);
strada.Fill(ds, "clue");
byte[] MyData = new byte[0];

DataRow myRow;
myRow = ds.Tables["clue"].Rows[0];
MyData = (byte[])myRow["Pic"];
MemoryStream stream = new MemoryStream(MyData);
pictureBox1.Image = Image.FromStream(stream);
con.Close();

// click print button
PrintDocument tmpDoc = new PrintDocument();
tmpDoc.PrintPage += new PrintPageEventHandler(Tmpdoc_Print);
PrintPreviewDialog tmpPpd = new PrintPreviewDialog();
tmpPpd.Document = tmpDoc;
tmpPpd.ShowDialog();
        
private void Tmpdoc_Print(Object sender, PrintPageEventArgs e)
{
   e.Graphics.DrawImage(pictureBox1.Image , 0,0);
}


但是打印小尺寸的图片不是真正的尺寸
我要打印真正尺寸为


but print picture with small size not really size
i want print picture with really size

推荐答案

的图片,请参阅我对问题的评论.您正在使用正确的DrawImage方法,该方法将以其原始大小(以像素为单位)打印图像:
http://msdn.microsoft.com/en-us/library/558kfzex.aspx [ ^ ].

您的原始图片可能太小,或者在将其串起之前先对其进行了重新采样.您没有显示此代码,因此请对其进行检查.同样,在这里使用类PictureBox可能毫无意义.在您的代码中,它什么也不做;您将图像本身用于打印,而不是控件.但是,如果您还想以最简单的方式在屏幕上显示图像,则可能真的想使用此控件.

—SA
Please see my comment to the question. You are using correct DrawImage method, which prints the image with its original size in pixels:
http://msdn.microsoft.com/en-us/library/558kfzex.aspx[^].

It may be possible that your original pictures are that small, or they were re-sampled down before string them. You did not show this code, so check it up. Also, using the class PictureBox might be pointless here. In your code, it does nothing; you use the image itself for printing, not the control. However, you might really want to use this control if you also want to show the image on screen in the simplest way.

—SA


这篇关于我要从数据库中打印图片,我要在图片框中显示图片,而不要打印包含图片框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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