asp.net image manipulation

windows

Guest
i havent done much at all with asp.net just kinda played a tiny bit looking at different scripts and such. i have pieced together this page pasted below because i want a simple page to be displayed on my webserver. i wanted something where i can just drag images over to the folder and have the page recognize the images and check/create a thumbnail for the image. i had it working at one point, but then it was giving a memory error. i then added the try...catch part in the middle because that was where the memory error was at. now im noticing that the page is not working correctly with the thumbnails. i have 78 images in a folder that are about 3mb each (7mpix). the script runs and eventually shows the thumbnails just like i want it to, but it takes a while and i noticed that its recreating all the thumbnails after the 23 image. maybe one of you can catch something obvious to a .net person and help me out. id like to learn .net, but havent had time at work to move up from classic. too many projects scheduled. some day, but for now... help!!! :)

<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" Debug="true" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<script language="vb" runat="server">
Function ThumbnailCallback() as Boolean
Return False
End Function

Const maxWidth as Integer = 200
Const maxHeight as Integer = 200

Sub Page_Load(sender as Object, e as EventArgs)
dim IMAGE_DIRECTORY as String = replace( Server.MapPath(Request.ServerVariables("PATH_INFO")),Path.GetFileName(Server.MapPath(Request.ServerVariables("PATH_INFO"))),"" )
Dim pics as ArrayList = new ArrayList()
Dim s as String, html as String
Dim currentImage as System.Drawing.Image
Dim imgHeight, imgWidth as Integer

For Each s in Directory.GetFiles( IMAGE_DIRECTORY ) ', "*.jpg" )
if not Path.GetFileName(s).indexof(".aspx") > 0 and not Path.GetFileName(s).indexof(".db") > 0 then
if not Directory.exists(IMAGE_DIRECTORY & "_tn") then
directory.CreateDirectory(IMAGE_DIRECTORY & "_tn")
end if
if not file.exists( "_tn\" & Path.GetFileName(s) ) then
'response.Write(s)
'response.End()
try
currentImage = 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

Dim dummyCallBack as System.Drawing.Image.GetThumbNailImageAbort
dummyCallBack = New System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)

Dim thumbNailImg as System.Drawing.Image
thumbNailImg = currentImage.GetThumbnailImage(imgWidth, imgHeight, dummyCallBack, IntPtr.Zero)

'thumbNailImg.Save( IMAGE_DIRECTORY & "_tn\" & Path.GetFileName(s),imageformat.jpeg)
thumbNailImg.Save( IMAGE_DIRECTORY & "_tn\" & Path.GetFileName(s),currentImage.rawformat)
catch
end try
end if

html = "<a href=http://www.webdeveloper.com/forum/archive/index.php/""" & Path.GetFileName(s) & """><img src=""_tn/" & Path.GetFileName(s) & """></a>"
html = html & "<br>" & Path.GetFileName(s)

pics.Add(html)
end if
Next

dlPictures.DataSource = pics
dlPictures.DataBind()
End Sub
</script>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<asp:DataList runat="server" id="dlPictures" RepeatColumns="3" ItemStyle-HorizontalAlign="Center" RepeatDirection="Horizontal">
<ItemTemplate>
<%# Container.DataItem %>
</ItemTemplate>
</asp:DataList>


</body>
</html>


posted this in the asp forum before i saw there was a .net forum.<!-- m --><a class="postlink" href="http://aspnet.4guysfromrolla.com/articles/012203-1.2.aspx">http://aspnet.4guysfromrolla.com/articl ... 3-1.2.aspx</a><!-- m --> I have been using this, but it is only really affective for one or two images at a time. Your applications are going to restart if you use it for lots of images (memory limit exceeded). The images really need to be saved. I am guessing this is similar to what you have in that respect. Watch this, <!-- m --><a class="postlink" href="http://quasi-ke.servebeer.com">http://quasi-ke.servebeer.com</a><!-- m --> , notice how many restarts I have and the top one being the last, then visit <!-- m --><a class="postlink" href="http://quasi-ke.servebeer.com/imggallery.aspx">http://quasi-ke.servebeer.com/imggallery.aspx</a><!-- m --> now go back to <!-- m --><a class="postlink" href="http://quasi-ke.servebeer.com">http://quasi-ke.servebeer.com</a><!-- m --> Boom, new restart. I am trying to figure out a really affective way to do what you want to do as well, one that does not involve me doing this one by one. I am thinking this is going to require just looping through the images and saving them as the script runs.the script i have as far as i can tell is looping through each image, checking for the thumbnail image and then creating and saving one for each image.is there something that i am missing in the code that is causing the page to not recognize the thumbnails that exist? or is there some cool tool for asp.net debugging so i could watch the problems?
 
Top