Victor Image Processing Library How-to Tips

Online Image File Converter

5starvic.jpg 5starvic.jpg converted online to 5starvic.gif
Original jpeg image Image converted to gif in real time by convert2.aspx

In ASP.NET the Victor Library functions can be called directly from a server application to create an online image file converter. In this example the file convert2.aspx receives the url of the image file to convert and the file type to convert it to.

The sequence of operations is

The ASP.NET file convert2.aspx can be assigned to a conventional image tag in an html file or to an image control in an asp.net application.

For a demonstration of an online image file conversion application http://www.catenary.com/demos/convert/convert.aspx .

ASP.NET Source Code (VB)




Online Image File Converter, the ASP.NET source code

In this .net page we load an image, convert it to the requested file format, and deliver it to the browser with a binary write. Requires Victor Image Processing Library for 32-bit Windows v 5.6 or higher.
<%@ Page %>
<html>
<head>
<title>convert2.aspx</title> 
<!-- #include file="vicdefs.aspx"  --> 
<!-- #include file="vicread.aspx"  --> 
      
<script runat="server">
sub Page_Load
dim fname() as string
dim ftype() as string
dim mode as integer              ' Compression parameter for savefile functions
dim transcolor as integer        ' Transparent color
dim quality as integer           ' Quality parameter for savejpg
dim srcimg as imgdes
dim tempimg as imgdes
dim bmh as BITMAPINFOHEADER
dim width as integer
dim length as integer
dim rcode as integer
dim outbuff as integer
dim imgbytearray as byte()
            ' Get the incoming file name and file type into which to convert it
   fname = Request.QueryString.GetValues("fname")   
   ftype = Request.QueryString.GetValues("ftype")   
            ' Load an image
    rcode = loadimagefromurl(fname, srcimg)    
    select case ftype(0)
        case "bmp" 
            mode = 0
            rcode = savebmptobuffer (outbuff, srcimg, mode)
            Response.ContentType = "image/bmp"
    
        case "gif" 
            getbmhfromimage(bmh, srcimg)        
            if(bmh.biBitCount = 24) then
                width = bmh.biWidth
                length = bmh.biHeight
            ' Create a temp image, copy of source image
                rcode = allocimage (tempimg, width, length, 24)
                if rcode = NO_ERROR then
                    rcode = copyimage (srcimg, tempimg) ' Copy src into the temp image buffer
                    if(rcode = NO_ERROR) then
                        freeimage (srcimg)          ' Release original image
            ' Create result image, new image replaces source image
                        rcode = allocimage (srcimg, width, length, 8)   ' Allocate new image
                        if(rcode = NO_ERROR) then
                            rainbowpalette (srcimg)                 ' Set a standard rainbow palette
                            matchcolorimageex (tempimg, srcimg, 3)  ' Create 8-bit version of temp into new source
                        end if 
                    end if 
                    freeimage (tempimg)
                end if
            end if 
            
            mode = 0
            transcolor = 0
            rcode = savegiftobufferex (outbuff, srcimg, mode, transcolor) 
            Response.ContentType = "image/gif" 
            
        case "jpg" getbmhfromimage(bmh, srcimg) 
            if(bmh.biBitCount = 1) then 
                width = bmh.biWidth 
                length = bmh.biHeight
            ' Create a temp image, copy of source image
                tempimg = new imgdes 
                rcode = allocimage (tempimg, width, length, 1) 
                if (rcode = NO_ERROR) then 
                    rcode = copyimage (srcimg, tempimg)
            ' Copy src into the temp image buffer
                    if(rcode = NO_ERROR) then 
                        freeimage (srcimg)  ' Release original image
            
            ' Create result image, new image replaces source image
                        rcode = allocimage (srcimg, width, length, 8)       ' Allocate new image
                        if(rcode = NO_ERROR) then 
                            rcode = convert1bitto8bit (tempimg, srcimg) ' Create grayscale of temp into new source
                        end if 
                    end if 
                    freeimage (tempimg) 
                end if 
            end if 
            quality = 75 
            rcode = savejpgtobuffer (outbuff, srcimg, quality) 
            Response.ContentType = "image/jpeg" 
        case "png" 
            mode = 0 
            rcode = savepngtobuffer (outbuff, srcimg, mode) 
            Response.ContentType = "image/png" 
            
        case "tif" 
            mode = 0 
            rcode = savetiftobuffer (outbuff, srcimg, mode) 
            Response.ContentType = "application/octet-stream" 
    end select 
            
    xit: freeimage (srcimg)
            ' Release image buffer
            ' Send the image to the browser
    if (rcode = NO_ERROR) then 
        imgbytearray = buffertobytearray(outbuff) 
        Response.Expires = 0 
        Response.Buffer = true 
        Response.Clear 
        Response.BinaryWrite(imgbytearray) 
        Response.End 
        
end sub 
</script> 
</head> 
<body> 
</body> 
</html> 
Victor Image Processing Library

Victor Image Processing Library homepage | Victor Product Summary | more source code




Copyright 2004 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.