在 C# 控制台应用程序中,如何生成 Google Charts API 请求并将结果保存为图像?
是否可以在控制台应用程序中调用 Google Charts API 并将结果保存为 JPEG 或 PNG 文件?我可以在网络应用程序中轻松完成此操作,只是不太确定如何在 C# 中完成此操作。
非常感谢
Is it possible to make a call to the Google Charts API in a console app and save the result as a JPEG or PNG file? I can do it easily in a web app, just not quite sure how to do it in C#.
Many thanks-
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 Charts API 的 googlechartsharp 包装器获取一个网址,您可以通过该网址查看图表。
使用
HttpWebRequest
和HttpWebResponse
类(或根据 Joey 的回答使用WebClient
类),您可以将响应流捕获为字节数组( image)并将其写入具有正确扩展名的文件(*.png 文件)。像这样的东西:You could use the googlechartsharp wrapper for the Charts API to get a URL at which you can view the chart.
Using the
HttpWebRequest
andHttpWebResponse
classes (or theWebClient
class as per Joey's answer), you could capture the response stream as a byte array (the image) and write that to a file with the proper extension (a *.png file). Something like:使用 WebClient 类及其 下载数据 或 DownloadFile 方法。构建要检索的 URL 由您决定。
Use the WebClient class and its DownloadData or DownloadFile methods. Constructing the URL to retrieve is up to you.
我添加了我的图表生成器类(工作完美)。只需调用它(如下所示)添加您自己的事件方法即可在生成图表后捕获图表并将其保存到 HDD。
调用类并生成图表:
实际类:
I added my Chart generator class (working perfectly). Just call it (as seen below) add your own event method to catch the chart once it is generated and save it to the HDD.
Calling the class and generating the chart:
The actual class: