PDA

View Full Version : [Giúp Đỡ Asp.net 4.0] - Upload hình lỗi - A generic error occurred in GDI+.



khongyeu09
15-07-2014, 17:46
Chào cả nhà, hiện tại mình đang làm trang web có một mudule up avatar. Up lên host thì bình thường, Vừa up xong chưa có ai xem cũng up lại được, nhưng nếu đã up và đã hiện trên trang người dùng thì không tai nào thay đổi được, kể cả xóa cái file ảnh đó. nó cứ báo lỗi. Muốn xóa mình phải recycle lại. Cho mình hỏi làm sao để khắc phục lỗi này được?
mình upload hình bằng đoạn sau:


private void UPLOADHINH(double scaleFactor, Stream sourcePath, string targetPath, int ChieuRong, int ChieuCao)
{
using (var image = System.Drawing.Image.FromStream(sourcePath))
{
var newWidth = (int)(ChieuRong);
var newHeight = (int)(ChieuCao);
var thumbnailImg = new Bitmap(newWidth, newHeight);
var thumbGraph = Graphics.FromImage(thumbnailImg);
thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
thumbGraph.DrawImage(image, imageRectangle);
thumbnailImg.Save(targetPath, image.RawFormat);
thumbnailImg.Dispose();
}
}

khi xóa thì nó báo lỗi

The process cannot access the file 'C:\Project6\giaodien\Website\Images\Shadow\bgTitl eCenter.png' because it is being used by another process.
giúp minh với! cảm ơn mọi người