Victor Library iconVictor Image Processing Library Application Notes

Creating an ASP.NET Online Image Processing Application

Browsers Display Image Files

Internet server applications are constrained by the limited ability of the browser to display images. To display an image the browser must have an html page that includes an <img> tag that defines the source of the image.

In a simple html page the <img> tag defines the source of the image to be the url of some gif, jpeg, or png file because browsers can only display images that are in those formats.

<img src=hibiscus.png">

An ASP.NET Page to Process and Display an Image

In ASP.NET we load an image, do some image processing, create the result image on-the-fly in gif, jpeg, or png format, and send it to the browser from an aspx page. The following image is a sharpened version of the hibiscus shown above. It is loaded by an aspx page, processed, then sent to the browser in jpeg format.

<img src="sharpen.aspx">

Below is the VB and C# source code for sharpen.aspx. The sequence is straight forward:

Sharpen.aspx source code -- C#

<%@  Page Language="C#" debug="true" %>
<%@  import namespace="System" %>
<%@  import namespace="System.Net" %>
<%@  import namespace="System.Runtime.InteropServices" %>
<%@  Import Namespace="viclib" %>

<html xmlns="">

<title>Victor Library Sample: sharpen.aspx</title>

<script runat="server">

    void Page_Load(object sender, EventArgs e)
        int rcode;
        int outbuff = 0;
        string fname;
        vicwin.imgdes vimage = new vicwin.imgdes();
        byte[] imgbytearray = new byte[1];        

        fname = "";

        // Load an image
        rcode = loadurlimage(ref vimage, fname);  // allocates space for image and loads it 

        if (rcode == vicwin.NO_ERROR)
            rcode = vicwin.sharpen(ref vimage, ref vimage);

        // Save it to a jpg file in memory, quality = 75
        rcode = vicwin.savejpgtobuffer(ref outbuff, ref vimage, 75);
        vicwin.freeimage(ref vimage);

        // Send the image to the browser
        if (rcode == vicwin.NO_ERROR)
            imgbytearray = buffer_to_bytearray(outbuff);

        Response.ContentType = "image/jpeg";
        Response.Expires = 0;
        Response.Buffer = true;
        Response.BinaryWrite(imgbytearray); // Send the image to the browser

Sharpen.aspx source code -- VB

<%@ Page debug="true" %>
<%@ import namespace="System" %> 
<%@ import namespace="System.Net" %> 
<%@ import namespace="viclib" %> 

<script runat="server">

sub Page_Load
dim ezimage as vicwin.imgdes
dim rcode as integer
dim outbuff as integer
dim imgbytearray as byte()

	' Load an image
	rcode = loadimagefromurl("hibiscus.png", ezimage)   ' Omitted here for easier reading 
	' Do some processing
	rcode = vicwin.sharpen(ezimage, ezimage)
	' Save it to a jpg file in memory, quality = 75
	rcode = vicwin.savejpgtobuffer(outbuff, ezimage, 75)
	' Send the image to the browser
	imgbytearray = buffertobytearray(outbuff) 	' Omitted here for easier reading

	Response.ContentType = "image/jpeg"
	Response.Expires = 0
	Response.Buffer = true

end sub



The functions sharpen, freeimage, and savejpgtobuffer are contained in the Victor Library and accessed through the viclib namespace.

Victor Image Processing Library

Victor Image Processing Library homepage

Copyright © 2005 - 2016 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.