Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I used below code to convert Image to Byte array
public static byte[] ConvertStringToBytes(string input)
        {
            MemoryStream stream = new MemoryStream();

            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.Write(input);
                writer.Flush();
            }

            return stream.ToArray();
        }


Now I want to re convert that byte array to Imagebitmap, i used below code

public BitmapImage ByteArraytoBitmap(Byte[] byteArray)
        {
            MemoryStream stream = new MemoryStream(byteArray);           

            byte[] bytes = byteArray as byte[];

            BitmapImage image = new BitmapImage();

            image.SetSource(stream);

            return image;
        }


But it gives error at 'image.SetSource(stream);' Unspecified error
Posted
Updated 13-Feb-14 6:56am
v2

1 solution

Well yes... It will.

But it's not the conversion from byte array to image that's the problem, it's the other method.

Look at the code: what is in the string? If it's image data, then it's probably corrupt from being converted to a string. But more likely, it's a file name or similar, rather than actual image data at all...

Use the debugger, and look at the string.
 
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