I want it to only saves the resized images so have tried to do so it deletes the original image again after it has been uploaded but can not because it says the image is being used by another process please help.
and can not simply remove where it stores the original because it uses it to resize
i Use this code to save the fils
string tempPath = "Galleryt";
string imgPath = "Gallery";
string savePath = Path.Combine(Request.PhysicalApplicationPath, tempPath);
string imgSavePath = Path.Combine(Request.PhysicalApplicationPath, imgPath);
string imgSavePath2 = Path.Combine(Request.PhysicalApplicationPath, imgPath);
string ProductImageNormal = Path.Combine(imgSavePath, imageName + Fileupload1.PostedFile.FileName);
string ProductImagetemp = Path.Combine(savePath, "t__" + imageName + Fileupload1.PostedFile.FileName);
string ProductImagetemp2 = Path.Combine(imgSavePath2, "b__" + imageName + Fileupload1.PostedFile.FileName);
string extension = Path.GetExtension(Fileupload1.PostedFile.FileName);
switch (extension.ToLower())
{
case ".png": goto case "Upload";
case ".gif": goto case "Upload";
case ".jpg": goto case "Upload";
case "Upload": Fileupload1.PostedFile.SaveAs(ProductImageNormal);
ImageTools.GenerateThumbnail(ProductImageNormal, ProductImagetemp, 250, 350, true, "heigh");
ImageTools.GenerateThumbnail(ProductImageNormal, ProductImagetemp2, 600, 600, true, "heigh");
Label1.Text = "";
break;
default:
Label1.Text = "Status: Denne filtype er ikke tilladt";
return;
}
if i try to delete the original file just after with code
File.Delete(Server.MapPath("~/Gallery/" + imageName + Fileupload1.PostedFile.FileName));
the method of GenerateThumbnail
public static void GenerateThumbnail(string filePath, string OriginalFile, int width, int height, bool retainAspect, string quality)
{
Bitmap bitmapNew;
float fx, fy, f;
int widthTh, heightTh;
int widthOrig, heightOrig;
bitmapNew = new Bitmap(filePath);
if (retainAspect)
{
widthOrig = bitmapNew.Width;
heightOrig = bitmapNew.Height;
fx = widthOrig / width;
fy = heightOrig / height;
f = Math.Max(fx, fy);
if (f<1)
{
f=1;
}
widthTh = (int)(widthOrig/f);
heightTh = (int)(heightOrig/f);
}
else
{
widthTh = width;
heightTh = height;
}
Size newSize = new Size(widthTh, heightTh);
using(Bitmap thumb = new Bitmap((System.Drawing.Image)bitmapNew, newSize))
{
Graphics g = Graphics.FromImage(thumb);
Int64 qualityLevel = 25L;
if (quality == "high")
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
qualityLevel = 95L;
}
if (quality == "medium" || quality == "low")
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
if (quality =="medium")
qualityLevel = 65L;
}
System.Drawing.Imaging.ImageCodecInfo codec = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()[1];
System.Drawing.Imaging.EncoderParameters eParams = new System.Drawing.Imaging.EncoderParameters(1);
eParams.Param[0]=new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityLevel);
//Her genereres den nye thumbnail
thumb.Save(OriginalFile, codec, eParams);
thumb.Dispose();
}
}