Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
1245111111111111111111111111111111115555555555555555555555556666

What I have tried:

Convert byte[] to image 4555519841199999998
Posted
Updated 16-Feb-18 22:38pm
v2
Comments
phil.o 17-Feb-18 4:14am    
Please have a look at the FAQ to know how to ask a question properly.

using (var ms = new MemoryStream(byteArrayIn))
{
    return Image.FromStream(ms);
}
See answers here for a JPG image: c# - Byte Array to Image Conversion - Stack Overflow[^]
 
Share this answer
 
v2
Comments
OriginalGriff 17-Feb-18 4:38am    
Um.
https://msdn.microsoft.com/en-us/library/93z9ee4x(v=vs.110).aspx
"You must keep the stream open for the lifetime of the Image."
RickZeeland 17-Feb-18 4:41am    
Hmmm, maybe copied that too hastily from StackOverflow ...
OriginalGriff 17-Feb-18 4:49am    
Plagiarism! Burn the heretic! :laugh:
Rick is right, up to a point. But the documentation is very clear:
Quote:
You must keep the stream open for the lifetime of the Image.
Image.FromStream Method (Stream) (System.Drawing)[^]
C#
using (MemoryStream ms = new MemoryStream(byteArrayIn))
    {
    using (Image im = Image.FromStream(ms))
        {
        return new Bitmap(im);
        }
    }
Is a lot safer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900