Last post Apr 18, 2018 09:20 PM by oneillj
Apr 17, 2018 11:11 PM|oneillj|LINK
Trying to display photos by paging through an array of objects with a path to the image. I want to re-dimension the photo on the fly based on the aspect ratio with CSS. I am using the Page_PreRender even and disabling the buttons so the user can't click
before a session variable with an index can be initialized or the I get a null value error. I'm not instantiating the image and every click to the next button is a postback. I think it might be because I'm constantly bringing up images with
every click. Here is the code...
protected void Page_PreRender(object sender, EventArgs e)
imgPhoto.ImageUrl = GetNextPhoto();
string path = HttpContext.Current.Server.MapPath(imgPhoto.ImageUrl);
int width = System.Drawing.Image.FromFile(path).Width;
int height = System.Drawing.Image.FromFile(path).Height;
if (width > height)
imgPhoto.CssClass = "photoLandscape";
imgPhoto.CssClass = "photoPortrait";
lbNext.Enabled = true;
lbPrevious.Enabled = true;
Apr 18, 2018 06:44 AM|Brando ZWZ|LINK
As far as I know, the out of memory exception means there is not enough memory to continue the execution of a program.
According to your codes,I couldn't find the codes which will cause the out of memory exception.
I suggest you could post more details codes about your issue.
For example, which line throw the error message.
If you could post more detail information, it will be more easily for us to find the solution.
Apr 18, 2018 07:13 AM|PatriceSc|LINK
FromFile does instantiate an image. I would use something such as :
width = img.Width;
height = img.Height;} // so that the image is disposed
It's best to be explicit about where it happens (you have this error on FromFile ???). Also could it be that it happens on a particular file ? Finally usually the image is really resized. Seems you size the image using CSS but you may end up in downloading
big images to just then show them with a smaller size while you could have saved some bandwidth.
Apr 18, 2018 08:02 PM|oneillj|LINK
Sorry about the lack of info. Throws on the first Image.FromFile().
Apr 18, 2018 08:03 PM|oneillj|LINK
I was wondering if there was a way to release the image. I will give that a try. I've optimized the images to where they are all well under 1mb. This only happens when it is uploaded to the hosting site.
Apr 18, 2018 09:20 PM|oneillj|LINK
Looks like that was it PatriceSC. Thanks for the answer.