How to generate dynamic C# images? [closed]

强颜欢笑 提交于 2019-12-10 11:25:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!