Using csImageLite with ASP.NET

csImageLite can be used with ASP.NET. The component must be registered on the server in the usual way and it can be called using Server.CreateObject. We have more details on component registration and running a COM component through component services on a 64 bit OS.

Example code to call the component in VB.NET:

Dim Image = Server.CreateObject("csImageLite.ImageFunctions")

Note the use of Dim compared with Set in classic ASP. For the trial version the class name is "csImageLiteTrial.ImageFunctions"

The above code uses late binding. A more efficient way of calling the component is to use early binding, which means creating a .NET equivalent assembly using the TLBIMP tool. Click here for more.

There are some incompatibilities between the data structures used by csImageLite and those of .NET, the most important being the method used to stream an image to the browser. This can no longer be done in a single line but the example below shows how it can be done in VB.NET.

<%@ Page language="vb" debug=true %>
  Response.Expires = 0
  Response.Buffer = true

  Dim Image = Server.CreateObject("csImageLite.ImageFunctions")

  Image.NewImage(150, 50, "00ff00")
  Image.TextOpaque = false
  Image.TextSize = 22
  Image.Text(5, 10, "Sample image")

  Dim OutArray As Array = Image.VariantOut("gif")
  Dim ByteArray(OutArray.Length - 1) As Byte
  Array.Copy(OutArray, ByteArray, OutArray.Length)
  Response.ContentType = "image/gif"

The last five lines of code take the image from csImageLite and stream it to the browser as a GIF. The output from the VariantOut property is read into OutArray which is then copied into an array of bytes called ByteArray. This array of bytes can be used in the Response.BinaryWrite command. In classic ASP the BinaryWrite command could take the value of VariantOut directly.

Sample Image

This is the sample image produced:

There are other differences in syntax between VBScript and VB.NET, mostly involving the use of brackets. In VBScript the NewImage and Text commands would not use brackets, but they do in VB.NET.

The code for streaming the image in C# is:

  Array OutArray = (Array)(Image.VariantOut("gif"));
  Byte[] ByteArray = new Byte[OutArray.Length];
  Array.Copy(OutArray, ByteArray, OutArray.Length);
  Response.ContentType = "image/gif";

With C#, early binding must be used.


This site uses cookies for functionality, traffic analysis and for targeted advertising. Click the Accept button to accept our Cookie Policy. The Cookie Policy page offers configuration for a reduced set of cookies for this site.