我需要保存并打印https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API中的图片,我已在cartesian live chart搜索过但我无法找到任何内容。我怎样才能做到这一点?我在Visual Studio 2012 Express中使用WinForms和C#。
答案 0 :(得分:1)
由于图表本身似乎不支持打印/拍摄屏幕图像,我建议您自己创建此功能。
您需要什么?
-
ScreenCapture sc = new ScreenCapture();
// capture entire screen, and save it to a file
Image img = sc.CaptureScreen();
// display image in a Picture control named imageDisplay
this.imageDisplay.Image = img;
// capture this window, and save it
sc.CaptureWindowToFile(this.Handle,"C:\\temp2.gif",ImageFormat.Gif);
如果你只需要控件的版画屏幕: C# Take ScreenShot of .net control within application and attach to Outlook Email
-
public static void TakeCroppedScreenShot( string fileName, int x, int y, int width, int height, ImageFormat format)
{
Rectangle r = new Rectangle(x, y, width, height);
Bitmap bmp = new Bitmap(r.Width, r.Height, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bmp);
g.CopyFromScreen(r.Left, r.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy);
bmp.Save(fileName, format);
}
-
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);
}
答案 1 :(得分:1)
您可以简单地将图形控件转换为this answer中所示的位图,然后将其保存到文件中。使用LiveCharts example中的图形控件(cartesianChart1
)
Bitmap bmp = new Bitmap(cartesianChart1.Width, cartesianChart1.Height);
cartesianChart1.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
bmp.Save("C:\\graph.png", ImageFormat.Png);
即使您的图形在另一个窗口后面,此方法也可以使用。
使用Tatranskymedved's answer打印图像。