0

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

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);
}

谢谢!

4

1 回答 1

1

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

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 
于 2012-08-16T04:50:33.120 回答