首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用PrintDialog使用BufferedGraphics打印

使用PrintDialog使用BufferedGraphics打印
EN

Stack Overflow用户
提问于 2012-08-16 12:35:44
回答 1查看 329关注 0票数 0

我有一个名为backbufferGraphics的BufferedGraphics,我想使用PrintDialog打印出缓冲中的内容,这是我的代码,但它不起作用:

代码语言:javascript
复制
private print()
{
        printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
        printDialog1.Document = printDocument1;
        printDialog1.AllowSelection = true;
        printDialog1.AllowSomePages = true;
        printDialog1.ShowDialog();
}
void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    DrawToPrint(e.Graphics);
}
private void DrawToPrint(Graphics _Gd)
{
    backbufferGraphics.Render(_Gd);
}

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2012-08-16 12:50:33

您必须首先在图像中设置缓冲区图形,然后打印图像:

代码语言:javascript
复制
Bitmap bmp = new Bitmap();

int X = e.X - bmp.Width/2;
int Y = e.Y - bmp.Height/2;
// créer et initialiser le BufferedGraphics
BufferedGraphics bg =
BufferedGraphicsManager.Current.Allocate(this.CreateGraphics(),
ClientRectangle);
Graphics g = bg.Graphics;

g.Clear(SystemColors.Control);
g.DrawImage(bmp, new Point(X, Y));

bg.Render();
g.Dispose(); 
bg.Dispose();
//save bmp as file 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11980798

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档