Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP.NET (Non-Forum Related)
 Newbie .Net error
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

laser
Advanced Member

Australia
3859 Posts

Posted - 19 November 2003 :  07:54:44  Show Profile
OK, it's late and I'm going to bed, so I might just be having one of those nights ...

I've just installed .Net, downloaded some working .Net code from my gallery at www.v8central.com/LFS but when I run this code on my machine I keep getting 'Out of memory' errors.

The exact error is :


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.OutOfMemoryException: Out of memory.

Source Error: 


Line 14:     For Each s in Directory.GetFiles(Server.MapPath(IMAGE_DIRECTORY), "*.jpg")    
Line 15:       'Get information about the image
Line 16:       Dim currentImage as System.Drawing.Image = System.Drawing.Image.FromFile(s)
Line 17:       
Line 18:       imgHeight = currentImage.Height
 

Source File: c:\internet\v8central\LFS\Default.aspx    Line: 16 

Stack Trace: 


[OutOfMemoryException: Out of memory.]
   System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement) +220
   System.Drawing.Image.FromFile(String filename) +7
   ASP.default_aspx.Page_Load(Object sender, EventArgs e) in c:\internet\v8central\LFS\Default.aspx:16
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +731


Running IIS 5.1 and .Net 1.1 and a fairly gutsy machine, rebooted, and still get this error.

Any ideas ?

WhatsUp
Starting Member

4 Posts

Posted - 19 November 2003 :  08:18:16  Show Profile  Visit WhatsUp's Homepage
How many images in the folder that you are working with?

It may be better to shell to a command prompt in the folder and execute dir /b *.jpg >image-list.txt

This can then be parsed on a line by line basis to get the image filename.
Go to Top of Page

laser
Advanced Member

Australia
3859 Posts

Posted - 19 November 2003 :  14:18:56  Show Profile
There's 23 images.

Wouldn't using a dir > txt achieve the same thing ? I'm still going to be looping around a list of filenames.
Go to Top of Page

laser
Advanced Member

Australia
3859 Posts

Posted - 19 November 2003 :  15:27:00  Show Profile
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.
Go to Top of Page

Nathan
Help Moderator

USA
7664 Posts

Posted - 19 November 2003 :  16:32:22  Show Profile  Visit Nathan's Homepage
Killing the aspnet_wp.exe process should remove the lock.

Nathan Bales
CoreBoard | Active Users Download
Go to Top of Page

laser
Advanced Member

Australia
3859 Posts

Posted - 19 November 2003 :  16:42:01  Show Profile
Thanks Nathan , interestingly enough I have to kill the aspnet_wp.exe process (and it doesn't really die, it just releases a ton of memory), then move the all the images out of the directory, then refresh the page, then move them back in - THEN it works.

Anyway, at least I can develop offline now.
Go to Top of Page

Nathan
Help Moderator

USA
7664 Posts

Posted - 19 November 2003 :  16:54:53  Show Profile  Visit Nathan's Homepage
humm . . . memory leak?

Nathan Bales
CoreBoard | Active Users Download
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.27 seconds. Powered By: Snitz Forums 2000 Version 3.4.07