Library code snippets
Embed text in Image using ASP.NET
Sometimes, it is nice to have a text caption embedded into an image, rather than display the caption in HTML. Fortunately, this is fairly straightforward in ASP.NET.
Look at this photo of myself. I can embed some text into the photo using the following code:
image_text.aspx
<%@ Page Language="c#"%>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Bitmap bmp= new Bitmap(Server.MapPath(Request.QueryString["i"]));
Graphics g=Graphics.FromImage(bmp);
g.SmoothingMode = SmoothingMode.AntiAlias ;
g.DrawString(Request.QueryString["t"],
new Font("verdana",12),SystemBrushes.WindowText, 1, 1);
Response.ContentType="image/jpeg";
bmp.Save(Response.OutputStream, bmp.RawFormat) ;
}
</script>
For a demo, take a look at http://www.charon.co.uk/demos/image_text.aspx?i=/file_library/images/articles/jules_photo.jpg&t=Photo+of+Jules. Play around with the querystring. See how the caption changes when you change the text in the querystring.
Related articles
Related discussion
-
Gizmox Announces release of Visual WebGui SDK version 6.2.2
by Visual WebGui (0 replies)
-
Error 4 Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).
by lbargers (3 replies)
-
How to receive data in web server sending from GPRS modem
by AshokSingh (1 replies)
-
Working with frames in c# .net
by pulak2008 (0 replies)
-
Time Out Problem
by lorrainepetty (1 replies)
Related podcasts
-
CodeCast Episode 4: State of .NET, IE8, ASP.NET MVC, and O'Reilly Media
CodeCast Episode 4: State of .NET, IE8, ASP.NET MVC, and O'Reilly MediaHosts Ken Levy and Markus Egger discuss the new State of .NET events, IE8, ASP.NET MVC, followed by an interview from PDC with two editors from O'Reilly Media. More on ASP.NET MVC can be found at http://asp.net/mvc. Interview...
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum) -
Microsoft Dynamics CRM Technical Consultant
in Netherlands (€50K-€90K per annum) -
.net developer
in Rijswijk (€2K-€4K per annum)
Events coming up
-
Dec
3
An afternoon of SQL Server Data Services and ASP.NET Dynamic Data
Bradford, United Kingdom
This event is in association with Black Marble. In the morning Black Marble will be presenting on Microsoft "Oslo": The Future of Enterprise Applications. To find out more about this please follow the link on the right.
how do I embed text without loosing the original quality of the image.
This thread is for discussions of Embed text in Image using ASP.NET.