views:

266

answers:

2

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.

A: 

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.

Rex M
+1  A: 

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.

Martin Peck