Creating dynamic images in ASP.NET

Written by Shanx March 9th, 2003

Creating dynamic images in ASP.NET

Continue reading →
Close

You might know that creating images in ASP was not possible without some sort of third party component or some plug-in to the browser or server. Many websites bought Macromedia Generator which could together with ASP create nice images on the server and then send them to the browser. But now with .NET and the new version of ASP.NET it has become embarassingly simple for everyone.

You might know that creating images in ASP was not possible without some sort of third party component or some plug-in to the browser or server. Many websites bought Macromedia Generator which could together with ASP create nice images on the server and then send them to the browser. But now with Microsoft.NET and the new version of ASP ASP.NET it has become embarassingly simple for everyone (if you only have ASP, then I’ve included links to some websites that make server-side objects for you to use).

In ASP.NET the namespaces section is crucial. With the right namespaces we are able to call and use properties and functions that is necessary for this
code to work. Please view comments in the code.


<%@ Page Language="VB" ContentType="image/jpeg" %>
<%@ import Namespace="System.Drawing" %>
<%@ import Namespace="System.Drawing.Imaging" %>
<%@ import Namespace="System.Drawing.Drawing2D" %>
<%
Response.Clear( )

'Set height and width of the image
Dim intheight As Integer = 400
Dim intwidth As Integer = 150

Dim bmpimage As new Bitmap(intwidth, intheight,
PixelFormat.Format24bppRgb)
Dim objimage as Graphics = Graphics.FromImage(bmpimage)

'Set alias and color to fill with
objimage.SmoothingMode = SmoothingMode.AntiAlias
objimage.Clear(Color.LightBlue)

'Set properties of the lines...
objimage.DrawRectangle(Pens.White,1,1,intwidth-3,intheight-3)
objimage.DrawRectangle(Pens.Black,1,1,intwidth,intheight)

 'Set text; what text, font and where to write it (two axis).
 objimage.DrawString("Kick-Ass!!!", _
New Font("Arial", 12, FontStyle.italic), _
SystemBrushes.WindowText, New PointF(30,50))
objimage.DrawString("Search and see", _
New Font("Arial", 12, FontStyle.italic), _
SystemBrushes.WindowText, New PointF(25,75))
objimage.DrawString("All .NET", _
New Font("Arial", 12, FontStyle.italic), _
SystemBrushes.WindowText, New PointF(35,150))
objimage.DrawString("www.ngcode.com", _
New Font("Arial", 8, FontStyle.Bold), _
SystemBrushes.WindowText, New PointF(20,200))

 'Display the image as a jpg
 bmpIMAGE.Save(Response.OutputStream, ImageFormat.Jpeg)
objimage.Dispose( )
bmpIMAGE.Dispose( )

Response.End( )

%>

Other recommended sites if you have ASP.NET

Other recommended sites if you only have ASP:

Posted in Miscellaneous

3 Comments

Tagged with

3 Comments

  1. joe says:

    Your article are great and very informative. I read your article on
    embedding text in to an image.

    I like to know how to embed a small image (small 10 by 10 gif file)
    into a larger image thats retrieve from the web (embed the image into
    the lower right corner) and then displaying it in a results HTML page.

    I know its probably very simple to you but I am scratching my head on
    this. Please provide some help on this.

    Your faithfull reader

  2. Neil says:

    Hi, I have the pearl version of imagemagick on an asp.net server. We are looking to do some basic conversions with gif files which we know can be done easily (make the gif transparent and change the color based on user input). We are not sure though, if a script will work on asp.net and if it can be done, how to do it. Can you help? Thanks!!

  3. Signs Of Change says:

    Thanks for the post, I have been stuck using ASPimage through my brinkster hosting account till I read your article, nice to know I have other options ;)

Leave a Reply

Miscellaneous

I use the Nokia e61i as my mobile. Instead of my telco’s data plan (which offers me a meagre 1GB per month) I simply prefer to use my home wireless [...]

Continue reading →

View all

Web Tools

If you use Firefox (and if not, what are you waiting for?) you are familiar with useful extensions such as Video Downloader, which allow you to save local copies of [...]

Continue reading →

View all

Databases

This regexp worked for me. SELECT * FROM table WHERE NOT column ~ ( ‘^(‘|| $$[\09\0A\0D\x20-\x7E]|$$|| — ASCII $$[\xC2-\xDF][\x80-\xBF]|$$|| — non-overlong 2-byte $$\xE0[\xA0-\xBF][\x80-\xBF]|$$|| — excluding overlongs $$[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|$$|| — straight 3-byte [...]

Continue reading →

View all

Windows

So you’ve been visited by the much dreaded CRC — Cyclical Redundancy Check error, most likely encountered while copying files between hard disks. On Mac OSX, this will usually appear [...]

Continue reading →

View all

Mac OSX

A simple app ought to do it. Download iRinger. It’s a Windows app. If you’re on Mac, you’ll want to use it within a virtual machine, like Parallels or VMWare [...]

Continue reading →

View all

System Maintenance

I use the Nokia e61i as my mobile. Instead of my telco’s data plan (which offers me a meagre 1GB per month) I simply prefer to use my home wireless [...]

Continue reading →

View all

Wordpress

Among many new exciting features, WordPress 2.6 released the ability to store each and every revision of your posts, like an elaborate update history. Now this can be a pretty [...]

Continue reading →

View all

Audio/Video

Panic, the makers of some fantastic software such as Transmit or Panic, also have the most light-weight audio converter for the Mac OSX platform. It’s called Audion: get it here. [...]

Continue reading →

View all

iPhone

A simple app ought to do it. Download iRinger. It’s a Windows app. If you’re on Mac, you’ll want to use it within a virtual machine, like Parallels or VMWare [...]

Continue reading →

View all