OK, by reducing the number of images I got it to display
but now the images seem to have a 'lock' on them, so I can't move them out of that directory for a while (sorry, I still haven't determined the time limit). I'm trying to learn .Net but I'm still at the Clueless Newbie stage.
The code I'm using is (default.aspx) :
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.IO" %>
<script language="vb" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
Const IMAGE_DIRECTORY as String = "/lfs/"
Const maxWidth as Integer = 200
Const maxHeight as Integer = 200
Dim pics as ArrayList = new ArrayList()
Dim s as String, html as String
Dim imgHeight, imgWidth as Integer
For Each s in Directory.GetFiles(Server.MapPath(IMAGE_DIRECTORY), "*.jpg")
'Get information about the image
Dim currentImage as System.Drawing.Image = System.Drawing.Image.FromFile(s)
imgHeight = currentImage.Height
imgWidth = currentImage.Width
If imgWidth > maxWidth OR imgHeight > maxHeight then
'Determine what dimension is off by more
Dim deltaWidth as Integer = imgWidth - maxWidth
Dim deltaHeight as Integer = imgHeight - maxHeight
Dim scaleFactor as Double
If deltaHeight > deltaWidth then
'Scale by the height
scaleFactor = maxHeight / imgHeight
Else
'Scale by the Width
scaleFactor = maxWidth / imgWidth
End If
imgWidth *= scaleFactor
imgHeight *= scaleFactor
End If
If imgHeight <> currentImage.Height Or imgWidth <> currentImage.Width then
html = "<a href=""" & IMAGE_DIRECTORY & Path.GetFileName(s) & """>" & _
"<img src=""ShowThumbnail.aspx?img=" & Path.GetFileName(s) & "&w=" & _
imgWidth & "&h=" & imgHeight & """ " & _
"height=""" & imgHeight & """ width=""" & imgWidth & """>" & _
"</a>"
Else
html = "<a href=""" & IMAGE_DIRECTORY & Path.GetFileName(s) & """>" & _
"<img src=""ShowThumbnail.aspx?img=" & Path.GetFileName(s) & """ " & _
"height=""" & imgHeight & """ width=""" & imgWidth & """>" & _
"</a>"
End If
pics.Add(html)
Next
dlPictures.DataSource = pics
dlPictures.DataBind()
End Sub
</script>
<html>
<body>
<h1>LFS pics</h1>
<p><hr><p>
<asp:DataList runat="server" id="dlPictures" RepeatColumns="3"
Width="600" CellPadding="5" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<%# Container.DataItem %>
</ItemTemplate>
</asp:DataList>
and ... ShowThumbnail.aspx
<%@Import Namespace="System.Drawing.Imaging" %>
<script language="VB" runat="server">
Function ThumbnailCallback() as Boolean
Return False
End Function
Sub Page_Load(sender as Object, e as EventArgs)
'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 = "/lfs/" & imageUrl
Dim fullSizeImg as System.Drawing.Image
fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath(imageUrl))
'Do we need to create a thumbnail?
Response.ContentType = "image/jpg"
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.Gif)
Else
fullSizeImg.Save(Response.OutputStream, ImageFormat.Gif)
End If
End Sub
</script>
What I'd really like to do at the moment is get rid of the lock on the images so I can then easily alter the code to do other things.