Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.NET cache dependency/files for data set..

Status
Not open for further replies.

talon121

IS-IT--Management
Jan 23, 2003
22
US
I have a website in ASP.Net that uses a gallery I created, that creates HTML for each cell in a table. using datalist control.

However, Im lost at where I start with caching the graphics (I use the system.graphic manipulation to create thumb of images).

Is there any way to cache the images I pull and write to the browser?

>> My code below. thu.aspx (code to create image thumb)
Code:
<%@Page Debug=True %>
<%@Import Namespace="System.Drawing.Imaging" %>
<script language="VB" runat="server">


  Dim homedir As String


  Function ThumbnailCallback() as Boolean
    Return False
  End Function


  Sub Page_Load(sender as Object, e as EventArgs)

    homedir += Request.QueryString("path")

  
    'Read in the image filename to create a thumbnail of
    Dim imageUrl as String = Request.QueryString("img")
    
    'Read in the width and height
    Dim imageHeight as Integer = Request.QueryString("h")
    Dim imageWidth as Integer = Request.QueryString("w")

    'Make sure that the image URL doesn't contain any /'s or \'s
    'If imageUrl.IndexOf("/") >= 0 Or imageUrl.IndexOf("\") >= 0 then
      'We found a / or \
    '  Response.End()
    'End If
    
    'Add on the appropriate directory
    imageUrl = homedir & imageUrl
    
    Dim fullSizeImg as System.Drawing.Image
    fullSizeImg = System.Drawing.Image.FromFile(imageUrl)

    'Do we need to create a thumbnail?
    Response.ContentType = "image/jpeg"
    If imageHeight > 0 and imageWidth > 0 then
      Dim dummyCallBack as System.Drawing.Image.GetThumbNailImageAbort
      dummyCallBack = New _
         System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)

      Dim thumbNailImg as System.Drawing.Image
      thumbNailImg = fullSizeImg.GetThumbnailImage(imageWidth, imageHeight, _
                                                   dummyCallBack, IntPtr.Zero)

      thumbNailImg.Save(Response.OutputStream, ImageFormat.jpeg)  
    Else
      fullSizeImg.Save(Response.OutputStream, ImageFormat.jpeg)  
    End If
    
  End Sub
</script>
Jason

---
LexiMedia, LLC Development Group
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top