Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Outputting images in ASP.NET: The hard way

View gist:2ac19a8acc87e1748e2c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
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.