asp.net consultancy chorley ASP.NET Server Side Scripting Wigan
Website Development Radcliffe

IT Services And Support

Email : ren@techsolus.co.uk
Mobile Phone : 0788 68 41 411
Answerphone : 01204 469683
bespoke invoice systems Standish Information Technology Advice Worsley
    development systems Ramsbottom
data manipulation Farnworth access databases Whitefield SQL connections Atherton
online accessible software Leyland software compatible Coppull


Get connected and Online Tottington
remote management Makerfield code and design Aspull

ASP.Net Running Code behind an image - 14/06/2012

Sometimes you want to serve an image, but you want a record of the image being served.  You may want some code to alter an image.  You may want to programatically choose an image to serve.  Whatever, this is a way to serve an image and run some code, in this case the code chooses which of three images to serve...

' start by choosing which pic to show
' pick a number between 1 and 3

 dim x as integer = system.datetime.now.millisecond
 if x > -1 and x < 334 then
  x = 1
 end if
 if x > 333 and x < 667 then
  x = 2
 end if
 if x > 666 then
  x = 3
 end if

' create the image location

 dim filename as string = server.mappath("\myimages\") & "thisimage" & x & ".jpg"

' serve the image

 dim servepic as new bitmap(filename)

 servepic.Save(Response.OutputStream, ImageFormat.jpeg)

 servepic.dispose

The key bit is...

dim servepic as new bitmap(filename)

 servepic.Save(Response.OutputStream, ImageFormat.jpeg)

 servepic.dispose

Post A Comment

Name Comment
programming services asp.net specialist
Valid XHTML 1.0 Transitional
Admin
GD