删除图片时出现图片被占用
/// <summary>
/// 生成缩略图,将缩略图文件保存到指定的路径
/// </summary>
/// <param name="Width">缩略图的宽度</param>
/// <param name="Height">缩略图的高度</param>
/// <param name="targetFilePath">缩略图保存的全文件名,(带路径),参数格式:D:\Images\filename.jpg</param>
/// <returns>成功返回true,否则返回false</returns>
public bool GetReducedImage(int Width, int Height, string targetFilePath)
{
double LengthLong; //存储(长和宽中)较短的长度
int widthOK, heightOK; //存储实际要生成的图片的长宽
if (Width < Height) //判断输入的长和宽那个较短
{
LengthLong = Width; //把较短的存储在 LengthLonh 用于计算
}
else
{
LengthLong = Height;
}
try
{
//判断原图片 长和宽
//原图比较长的一个边要和缩略图的边相等
if (ResourceImage.Width > ResourceImage.Height)
{
widthOK = (int)LengthLong;
heightOK = (int)(LengthLong / ResourceImage.Width * ResourceImage.Height);
}
else
{
heightOK = (int)LengthLong;
widthOK = (int)LengthLong / ResourceImage.Height * ResourceImage.Width;
}
Image.GetThumbnailImageAbort callb = new Image.GetThumbnailImageAbort(ThumbnailCallback);
ReducedImage = ResourceImage.GetThumbnailImage(widthOK, heightOK, callb, IntPtr.Zero);
ReducedImage.Dispose();
ReducedImage.Save(@targetFilePath, ImageFormat.Jpeg);
//ReducedImage.Dispose();
return true;
}
catch (Exception e)
{
ErrMessage = e.Message;
return false;
}
}
生成缩略图后,删除原文件提示原文件被占用删除不了.(Big2009481647513131.jpg' because it is being used by another process. )