я должен изменить размер изображения каталога,Изменение размеров всех изображений в каталоге
, но я получаю сообщение об ошибке, доступ запрещен, на этой линии
System.IO.File.Delete(_path);
я знаю, что это потому, что образ я прочитанный в использовании, но не знают, как справиться с этим
я нашел ссылки на SO, но все они находятся в PHP :-(
for (int i = 1; i < dt.Rows.Count; i++)
{
try
{
string _ImageUrl = HttpContext.Current.Request.PhysicalApplicationPath +
"Data\\" + dt.Rows[i]["ProductImage"].ToString();
string _extName = System.IO.Path.GetExtension(_ImageUrl);
System.Drawing.Image _productImage = ImageReSize(_ImageUrl, 500);
string _path = _ImageUrl;
if (System.IO.File.Exists(_path))
System.IO.File.Delete(_path);
_productImage.Save(_path);
_productImage = ImageReSize(_ImageUrl, 85);
string _strImageName2 = dt.Rows[i]["ProductSmallImage"].ToString();
_path = HttpContext.Current.Request.PhysicalApplicationPath +
"Data\\" + _strImageName2;
if (System.IO.File.Exists(_path))
System.IO.File.Delete(_path);
_productImage.Save(_path);
}
}
код изменения размера
public System.Drawing.Image ImageReSize(string _imageUrl, int Width)
{
try
{
//uploadImageFile.PostedFile.InputSteam
System.Drawing.Image oImg = System.Drawing.Image.FromFile(_imageUrl);
//((oh *nw)/ow)*100
int Height = ((oImg.Height * Width)/oImg.Width); // (oImg.Width * Width);
Size PictureThumbSize = new Size();
PictureThumbSize.Height = Height;
PictureThumbSize.Width = Width;
System.Drawing.Image oThumbNail = new Bitmap(PictureThumbSize.Width, PictureThumbSize.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Graphics oGraphic = Graphics.FromImage(oThumbNail);
oGraphic.CompositingQuality = CompositingQuality.HighQuality;
oGraphic.SmoothingMode = SmoothingMode.HighQuality;
oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
Rectangle oRectangle = new Rectangle(0, 0, PictureThumbSize.Width, PictureThumbSize.Height);
oGraphic.DrawImage(oImg, oRectangle);
oImg.Dispose();
return oThumbNail;
//oThumbNail.Save(sPhysicalPath + @"\" + newFileName, ImageFormat.Jpeg);
}
catch (Exception Ex)
{
return null;
}
}
Доступ запрещен где? Какая линия? Помогите нам помочь. – Nolonar
я отредактировал сообщение, пожалуйста, посмотрите еще раз, спасибо –
Код 'ImageReSize'? – JeffRSon