2012-08-16 71 views
0

BufferedGraphics我有一個名爲BufferedGraphics和backbufferGraphics我想打印出來使用PrintDialog類緩存中的內容,這是我的代碼,但它不是工作:打印使用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); 
} 

謝謝!

回答

1

你必須先設置你的buffergraphics一個圖像中和後,你將打印圖像:

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