问题
Basically, I want to rehash VisualCube, written previously in PHP.
I've looked into GDI+, tried to find books that dealt with C#, graphics, etc.
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.
What technologies can I use for this? If GDI+, can someone provide me a usage in WebAPI/WCF?
I'd be accessing the WebAPI/WCF through MVC4.
回答1:
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");
}
}
回答2:
You could check here: using-wpf-to-generate-a-bitmap
http://social.msdn.microsoft.com/Forums/vstudio/en-US/2857e468-c32a-45dd-be02-cbd920259950/using-wpf-to-generate-a-bitmap-or-other-image-on-an-aspnet-web-application-form
来源:https://stackoverflow.com/questions/18233097/how-to-generate-dynamic-c-sharp-images