Uthistran Selvaraj
Uthistran Selvaraj

Reputation: 1371

String[] to image gets failed

I have an array of string from which I need to Draw an image in Windows forms.

I've done the following two steps:

  1. converted the string array into memory stream.
  2. and used the following code:

    Image image = Image.FromStream(memory stream);
    

But it always returns null.

Upvotes: 0

Views: 120

Answers (1)

Roman Melnyk
Roman Melnyk

Reputation: 1097

You can get image from byte array:

public Image byteArrayToImage(byte[] byteArrayIn)
{
     MemoryStream ms = new MemoryStream(byteArrayIn);
     Image returnImage = Image.FromStream(ms);
     return returnImage;
}

Be aware with formats. For example, Silverlight and WPF support only JPEG or PNG. Otherwise will get an exception.

Upvotes: 1

Related Questions