Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Outputting images in ASP.NET: The hard way
byte[] objImgData = ConvertImageToByteArray(new Bitmap(fileName), ImageFormat.Jpeg);
MemoryStream objMemoryStream = new MemoryStream();
objMemoryStream.Write(objImgData, 0, objImgData.Length);
Image objImage = Image.FromStream(objMemoryStream);
HttpContext.Current.Response.AddHeader("Content-Disposition", "filename=" + fileName);
HttpContext.Current.Response.ContentType = "image/Jpeg";
objImage.Save(HttpContext.Current.Response.OutputStream, ImageFormat.Jpeg);
...
private byte[] ConvertImageToByteArray(Image objImageToConvert, ImageFormat objFormatOfImage)
{
byte[] objByteImage;
using (MemoryStream objMemoryStream = new MemoryStream())
{
objImageToConvert.Save(objMemoryStream, objFormatOfImage);
objByteImage = objMemoryStream.ToArray();
}
return objByteImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.