是否可以将 ASP.NET 控件即时转换为图片?
在 ASP.NET 中,如果我有一个多行文本框(甚至是第 3 方富文本框),我可以在回发期间将其内容转换为图片吗? 通过转换我的意思是保持格式和 图片中的内容。
例如,我有一个富文本编辑框,最终用户可以直接在其上添加精美的文本字体和符号,一旦他们点击“提交”,有没有办法将此富文本内容保存为位图? 或者是否有这样的第三方丰富的编辑框具有此内置功能?
我猜它可能需要 GDI+ 或 WPF,但只是不知道从哪里开始。
In ASP.NET, If I have an multi-line text box (or even a 3rd party rich text box), can I convert its content to a picture during postback? By convert I mean to keep the format & content in the picture.
For example, I have a rich edit box, end user can add fancy text font and symbols directly on it, once they hit "submit", is there a way to save this rich text content as a bitmap? or is there such a 3rd party rich edit box having this built-in feature?
I guess it might need GDI+ or WPF, but just don't know where to start.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定之前的答案是否解决了您的问题。 您想要捕获最终用户(即浏览器)窗口中显示的内容,对吗? 然后您想将 BMP 发布回您的服务器。 据推测,您想要这样做是因为最终用户可能拥有您没有的字体支持等,或者您希望他们向没有这些支持的其他用户显示此图像。
我很确定这在浏览器中是不可能的。 这听起来也应该很困难(我不想看到可以轻松捕获我的桌面窗口区域并将其发回的网站)。 我怀疑您正在编写自己的 ActiveX/Silverlight/Flash 控件,但您应该考虑这是否是明智之举 - 您是否可以控制您的浏览器(换句话说,您能否保证浏览器版本)以及您的用户拥有的操作系统)? 如果没有,您可能会发现让屏幕捕获控件在操作系统/浏览器矩阵的所有部分上工作的工作量大于其价值。
也许如果你扩展你的问题,可以找到更好的解决方案,或者更有可能找到完全不同的方法。
I'm not sure the previous answer addressed you problem. You want to capture what's being displayed in the end users (i.e. the browsers) window, right? And then you want to post BMP back to your server. Presumably, you want to do this because the end user might have font support etc that you don't have, or that you want to them show this image to other users that don't have them.
I'm pretty sure that this isn't possible within a browser. It sounds like something that should be difficult too (I'd hate to see websites that could easily capture areas of my desktop window and post them back). I suspect you're in the realms of writing your own ActiveX/Silverlight/Flash control, but you should consider whether this is a sensible thing to do - do you have control over your browsers (in other words, can you guarentee the browser version and OS that your users have)? If not, you might find that getting a screen capture control working on all parts of the OS/browser matrix is more work than it's worth.
Perhaps if you expand on your problem a better solution can be found or, more likely, a totally different approach.
这是一个非常令人讨厌、丑陋的代码示例,但它一次性涵盖了所有概念: 如何使用 ASP.NET 动态创建 (a) 文本图像。
本质上,这是通过创建一个新的 System.Drawing.Bitmap< 来完成的/a> 并使用 System.Drawing.Graphics.DrawString (文本)。 它需要估计绘制的绳子有多大,并确保你的画布足够大; 设置字体之类的,但总的来说,一旦你做了几次,就很简单了。
This is a really nasty, ugly code sample, but it covers all the concepts in one go: How to Create (a) Text Image on the fly with ASP.NET.
Essentially this is done by creating a new System.Drawing.Bitmap and using System.Drawing.Graphics.DrawString(text). It requires estimating how large the drawn string will be and ensuring your canvas is large enough; setting up fonts and the like, but overall it's pretty simple once you do it a few times.