You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to render picturebox image bytearray as jpg and not png? #1311
Hi.
I noticed about others posts that the way to load a PictureBox.Image from bytearray is like:
using (var ms = new MemoryStream(_imageBytes))
{
var img = Image.FromStream(ms); //here imageformat stills ImageFormat.Jpeg
_image = new Bitmap(img); // here changes to ImageFormat.MemoryBmp
picBoxImage.Image = _image;
}
But i want smaller response sizes.
Original memory stream is about 70k (jpg encoded), but is rendered to client as png with bigger size (700k), last is a bit slow when 15 or more images
I want to know a way to response as jpg or better approach
Thanks in advance!
Activity
itg-assistant commentedon Jun 12, 2026
Luca answered 2018-01-16 17:37:40 UTC
You need to keep the byte array stream. The code in your message disposes the stream and creates a new bitmap. Do this instead:
picBoxImage.Image = Image.FromStream(new MemoryStream(_imageBytes));
Jpeg images in System.Drawing need the stream.
Otherwise you can also save the image to a temp file and return the name of the file.