Image does not contain a definition for Fromstream

Asked

Viewed 175 times

1

I’m using a method to convert a array of bytes of an image in the database in an image but the code says that Image does not contain a definition for FromStream().

private Image ConversaoByteparaImagem(byte[] arraybytes)
    {
        MemoryStream ms = new MemoryStream(arraybytes);
        Image imagem = Image.FromStream(ms);
        return imagem;
    }

Line where error occurs:

Image imagem = Image.FromStream(ms);
  • The error is very clear. What is the namespace of Image?

  • System.Windows.Controls

1 answer

2


In fact this class does not have the method FromStream() as shown at documentation. I would need to see what you want to do and find another solution, but the mistake is clear and this cannot be done. The Windows Forms class has this method, according to documentation. If you use it then you can do what you want, but I can’t say it is a good solution (it may work, but only understanding the problem in detail to analyze). Using so should solve the specific problem (even if it causes some other):

using System.Drawing;

probably in place of:

using System.Windows.Controls;

It is not working for other reasons (it does not have a valid data, but the error it claims to have does not happen with the namespace correct), so:

using System.IO;
using System.Drawing;

public class Program {
    public static void Main() {
        Image.FromStream(new MemoryStream(new byte[1024]));
    }
}

Behold working in the ideone. And in the .NET Fiddle. Also put on the Github for future reference.

  • He’s probably confused with the class Image of System.Drawing.

  • I tried using with System.Drawing and he doesn’t even recognize Image

  • 1

    @LINQ should indeed be this, put example showing "working" since it states that the error persists.

  • I tried the new code but he keeps saying it doesn’t contain a definition

  • I showed it working, you’re not doing what I did.

  • I am doing, I used the code along with the namespaces and yet it continues to inform that it has no definition for Filestream

  • Then use the FromStream() that’s what you wanted to wear.

  • apparently the error was with the IDE,I restarted the program and was error free

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.