简体   繁体   English

如何实时渲染图像

[英]How to render images in real-time

I am looking for a solution\\software that I can use in order to render buttons in real time. 我正在寻找可用于实时呈现按钮的解决方案\\软件。 That is, I have an image and text, and I want them to be an image altogether in realtime. 也就是说,我有一个图像和文本,并且希望它们完全实时地成为图像。

Thank you 谢谢

You can dynamically create an image based on text using the System.Drawing namespace. 您可以使用System.Drawing命名空间基于文本动态创建图像。

private Bitmap CreateBitmapImage(string imageText, string imageUrl)
{
    Bitmap myBitmap = new Bitmap(imageUrl);
    Graphics g = Graphics.FromImage(myBitmap);
    g.DrawString(imageText, new Font("Tahoma", 40), Brushes.White, new PointF(0, 0));

    return (objBmpImage);
}

Once you have the Bitmap object in memory you can save it to the disk and call it's location from the web. 将Bitmap对象存储在内存中后,您可以将其保存到磁盘并从Web调用其位置。

Bitmap bmp = CreateBitmapImage("my picture", @"C:\myBasePic.bmp");
bmp.Save(@"C:\bla.png", System.Drawing.Imaging.ImageFormat.png);

It would be good if you can specify why such requirement is there. 如果您可以指定为什么存在此要求,那将是很好的。 One of such scenario that I had encountered was need of image buttons with different text (round corners with shaded background) - this can easily be achieved using CSS. 我遇到的这种情况之一就是需要带有不同文本的图像按钮(带有阴影背景的圆角)-使用CSS可以轻松实现。 If you really want to combine an image and text together then you can do that at server side (using say System.Drawing types) and serve the combined image over a handler/web-service. 如果您真的想将图像和文本组合在一起,则可以在服务器端执行此操作(使用诸如System.Drawing类型),然后通过处理程序/ Web服务提供组合的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM