Invalid parameter, Memorystream

Asked

Viewed 363 times

2

Good afternoon guys, I’m developing a small project in that needs to present an image together with a recipe and it is the first time I work with image in database, I already inserted the image in the database. Already in the project(C#) when I pass the type parameter MemoryStream of error:

Invalid parameter.

var receitaP1 = cmd.ExecuteReader();

while (receitaP1.Read())
{
    receita.CodReceita = Convert.ToInt16(receitaP1["codReceita"].ToString());
    receita.NomeReceita = receitaP1["nomeReceita"].ToString();
    receita.ModoPreparo = receitaP1["modoDePreparo"].ToString();
    receita.Tipo = receitaP1["nomeTipo"].ToString();

    byte[] imagem = (byte[]) receitaP1["imagem"];
    MemoryStream memoria = new MemoryStream(imagem);

    Image image = Image.FromStream(memoria); //"Memoria" >>> Erro: parametro invalido!

    receita.Imagem = image;
}

Check it out, it’s already position 0

inserir a descrição da imagem aqui

Insert in the database: inserir a descrição da imagem aqui

  • can show the generated stacktrace?

  • 1

    It is possible that the contents of your byte[] has not been saved as a valid image, then? I only see this alternative not to be working. Test convert your byte array to base64string (var b64 = Convert.ToBase64String(imagem);) and use a online converter to confirm that the.

  • show how you are saving the image in the bank

  • Ready, I made the Insert from an example I picked up on the internet

No answers

Browser other questions tagged

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