protected void btnCropIt_Click(object s, EventArgs e)
{
System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("../upload/" + u.Avatar));
var m = cropImage(img, new Rectangle(0, 0, 50, 50));
System.IO.File.Delete(Server.MapPath("../upload/" + u.Avatar));
m.Save(Server.MapPath("../upload/" + u.Avatar));
}
private static System.Drawing.Image cropImage(System.Drawing.Image img, Rectangle cropArea)
{
Bitmap bmpImage = new Bitmap(img);
Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);
return (System.Drawing.Image)(bmpCrop);
}
System.IO.File.Delete(Server.MapPath("../upload/" + u.Avatar));
这行代码抛出无法删除图像的异常,它被另一个进程使用。任何想法?如何覆盖它?