![]() |
![]() |
| 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
<img src = "convert2.aspx?ftype=gif&fname=http://www.catenarysystems.com/5starvic.jpg" >To invoke convert2.aspx from an ASP.NET page
image1.imageurl = "convert2.aspx?ftype=gif&fname=http://www.catenarysystems.com/5starvic.jpg"
For a demonstration of an online image file conversion application http://www.catenarysystems.com/demos/convert/convert.aspx.
<%@ 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 homepage | Victor Product Summary | more source code