below is my code which throws exception because i am using the 'using' statement with the memory stream, i.e. it gets disposed at the end and when i try to save the image it throws the exception.
using(MemoryStream memoryStream = new MemoryStream())
{
ImageCodecInfo imageEncoder = GetEncoderInfo("image/jpeg");
EncoderParameter qualityParam = new EncoderParameter(Encoder.Quality, quality);
EncoderParameters encodeParams = new EncoderParameters(1);
encodeParams.Param[0] = qualityParam;
using (Bitmap bitmapImage = new Bitmap(image, width, height))
{
bitmapImage.SetResolution(dpi, dpi);
bitmapImage.Save(memoryStream, imageEncoder, encodeParams);
}
Image compressedImage = new Bitmap(memoryStream);
}
_compressedImage.Save("C:\\test.jpg");