如何生成动态的C#图像?
基本上,我想在PHP pviously老调重弹 VisualCube ,书面$ P $。
Basically, I want to rehash VisualCube, written previously in PHP.
我看着GDI +,试图寻找书籍,用C#,图形等。
I've looked into GDI+, tried to find books that dealt with C#, graphics, etc.
一切都有点相关的是针对只的WinForms或WPF,而我呢,最好要创建提供了图像的WebAPI或WCF服务。
Everything somewhat relevant is aimed at only WinForms or WPF, while I'd ideally want to create a WebAPI or WCF service that serves up the images.
我可以使用哪些技术呢?如果GDI +,有人可以提供我一个使用情况的WebAPI / WCF?
What technologies can I use for this? If GDI+, can someone provide me a usage in WebAPI/WCF?
我要访问的WebAPI / WCF通过MVC4。
I'd be accessing the WebAPI/WCF through MVC4.
Hanselman有与解释的例子:
http://www.hanselman.com/blog/BackToBasicsDynamicImageGenerationASPNETControllersRoutingIHttpHandlersAndRunAllManagedModulesForAllRequests.aspx
Hanselman has an example with explanation: http://www.hanselman.com/blog/BackToBasicsDynamicImageGenerationASPNETControllersRoutingIHttpHandlersAndRunAllManagedModulesForAllRequests.aspx
public ActionResult DynamicImage()
{
using (Bitmap image = new Bitmap(200, 200))
{
using (Graphics g = Graphics.FromImage(image))
{
string text = "Hello World!";
Font drawFont = new Font("Arial", 10);
SolidBrush drawBrush = new SolidBrush(Color.Black);
PointF stringPonit = new PointF(0, 0);
g.DrawString(text, drawFont, drawBrush, stringPonit);
}
MemoryStream ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return File(ms.ToArray(), "image/png");
}
}