Reputation: 231
I've an image in asp.net application and I resize and convert it for several times , but sometimes it's used by IIS Express process. and I can't resize or convert it. How to free IIS Express handle or how to bypass it? is engaging IIS Express before publishing normal or I should exactly handle such situation?
this piece of code is for replacing two images:
public static void Replace(string OldPicture, Stream NewPicture)
{
Bitmap OldImage = new Bitmap(OldPicture);
ImageFormat format = OldImage.RawFormat;
Bitmap NewImage = new Bitmap(NewPicture);
OldImage.Dispose();
NewImage.Save(OldPicture, format);
NewImage.Dispose();
return;
}
Oldpicture is in use while saving via NewImage.save
Upvotes: 0
Views: 237
Reputation: 171
It's happen if the File is open. Possible you have to call .Dispose()
or work with using(...){...}
.
Dispose Example:
Bitmap source = new Bitmap(filePath);
Rectangle croptRect = new Rectangle((int)cropX, (int)cropY, (int)resizeWidth, (int)resizeHeight);
Bitmap target = source.Clone(croptRect, source.PixelFormat);
source.Dispose();
// working ...
target.Dispose();
Using Example:
if (!File.Exists(_path)) using (File.Open(_path)) { }
Upvotes: 1