Reputation: 845
I am using
File.Delete("new13.jpg");
FileStream stream1 = new FileStream("new13.jpg", FileMode.Create);
JpegBitmapEncoder encoder1 = new JpegBitmapEncoder();
encoder1.FlipHorizontal = true;
encoder1.FlipVertical = false;
encoder1.QualityLevel = 30;
//encoder.Rotation = Rotation.Rotate90;
encoder1.Frames.Add(BitmapFrame.Create(bitmap));
encoder1.Save(stream1);
when my camera takes a new picture it is stored as "new13.jpg" but when i again take picture it shows exception that this image it is being used by another process . I am doing some image processing on image after being taken. How do i get rid of this exception .
Upvotes: 2
Views: 233
Reputation: 128060
You should close the stream after saving to it:
encoder1.Save(stream1);
stream1.Close();
Or better use a using block like this:
using (FileStream stream = new FileStream("new13.jpg", FileMode.Create))
{
encoder1.Save(stream);
}
Upvotes: 4