li ho messi già i Dispose
, può essere un problema d server ke l'ASP.NET sia configurato in modo errato?
cmq ti posto lo script
codice:
<%@ Page Language="C#" Debug="true"%>
<%@ import Namespace="System.Drawing" %>
<%@ import Namespace="System.Drawing.Imaging" %>
<%@ import Namespace="System.Text.RegularExpressions" %>
<%@ import Namespace="System.IO"%>
<script runat="server">
int MaxWidth; // Larghezza massima dopo il quale l'immagine viene ridimensionata
int MaxHeight; // Altezza massima dopo il quale l'immagine viene ridimensionata
int MaxWidth_thumb;
int MaxHeight_thumb;
int ScaleFactor;
System.Drawing.Image oldImage, newImage, newImage_thumb;
void Page_Load(Object sender, EventArgs e) {
if ( Request.QueryString["FileName"] != null ) {
string strFileName;
string in_dir_tekstudio;
if (Request.QueryString["id"] != null){
strFileName = Convert.ToString("temp/"+Request.QueryString["FileName"]);
if (Request.QueryString["FileName"]=="immagine.jpg"){
MaxWidth = 400;
MaxHeight = 400;
MaxWidth_thumb = 190; // X le img da copertina
MaxHeight_thumb = 250;
}else{
MaxWidth = 640;
MaxHeight = 480;
MaxWidth_thumb = 120; // X le img x skede
MaxHeight_thumb = 120;
}
}
else{
strFileName = Convert.ToString("temp/immagine_biografia.jpg");
MaxWidth = 400;
MaxHeight = 400;
MaxWidth_thumb = 270; // X la biografia
MaxHeight_thumb = 200;
}
if ( strFileName != "" ) {
try {
oldImage = System.Drawing.Image.FromFile(Server.MapPath(strFileName));
// Immagine troppo grande, visualizzo la miniatura
if (oldImage.Width > MaxWidth){
newImage = oldImage.GetThumbnailImage(MaxWidth, (oldImage.Height*MaxWidth/oldImage.Width), null, IntPtr.Zero);
newImage_thumb = oldImage.GetThumbnailImage(MaxWidth_thumb, (oldImage.Height*MaxWidth_thumb/oldImage.Width), null, IntPtr.Zero);
}else{ if (oldImage.Height > MaxHeight){
newImage = oldImage.GetThumbnailImage((oldImage.Width*MaxHeight/oldImage.Height), MaxHeight, null, IntPtr.Zero);
newImage_thumb = oldImage.GetThumbnailImage(MaxHeight_thumb, (oldImage.Width*MaxHeight_thumb/oldImage.Height), null, IntPtr.Zero);
}else
newImage = oldImage.GetThumbnailImage(oldImage.Width, oldImage.Height, null, IntPtr.Zero);
}
newImage_thumb = oldImage.GetThumbnailImage(MaxWidth_thumb, (oldImage.Height*MaxWidth_thumb/oldImage.Width), null, IntPtr.Zero);
Response.ContentType = "image/jpeg";
newImage.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
newImage_thumb.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
Environment.CurrentDirectory=AppDomain.CurrentDomain.BaseDirectory;
if (Request.QueryString["id"] != null){
newImage.Save("img/"+Request.QueryString["id"]+"/"+Request.QueryString["FileName"],System.Drawing.Imaging.ImageFormat.Jpeg);
newImage_thumb.Save("img/"+Request.QueryString["id"]+"/thumbs/"+Request.QueryString["FileName"],System.Drawing.Imaging.ImageFormat.Jpeg);
}else{
newImage.Save("img/immagine_biografia.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
newImage_thumb.Save("img/thumbs/immagine_biografia.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
}
oldImage.Dispose();
newImage.Dispose();
newImage_thumb.Dispose();
newImage_thumb = null;
oldImage = null;
newImage = null;
} catch (Exception ex) {
Response.Write(ex.Message);
}
System.IO.File.Delete(Server.MapPath(strFileName));
}
}
}
</script>