Saltar al contenido

convertir imagen a byte array ejemplo de código c # en línea

Este team de trabajo ha estado largas horas buscando soluciones a tu duda, te dejamos la respuestas de modo que esperamos serte de mucha ayuda.

Ejemplo 1: imagen de c # en byte array

publicbyte[]ImageToByteArray(System.Drawing.Image imageIn)using(var ms =newMemoryStream())
      imageIn.Save(ms,imageIn.RawFormat);return  ms.ToArray();

Ejemplo 2: imagen a byte array C#

usingSystem;usingSystem.Drawing;usingSystem.Windows.Forms;usingSystem.IO;namespaceWindowsFormsApplication1publicpartialclassForm1:FormpublicForm1()InitializeComponent();privatevoidbutton1_Click(object sender,EventArgs e)//image to byteArrayImage img = Image.FromFile("d:\bank-copy.png");byte[] bArr =imgToByteArray(img);//byte[] bArr = imgToByteConverter(img);//Again convert byteArray to image and displayed in a pictureboxImage img1 =byteArrayToImage(bArr);
            pictureBox1.Image = img1;//convert image to bytearraypublicbyte[]imgToByteArray(Image img)using(MemoryStream mStream =newMemoryStream())
                img.Save(mStream, img.RawFormat);return mStream.ToArray();//convert bytearray to imagepublicImagebyteArrayToImage(byte[] byteArrayIn)using(MemoryStream mStream =newMemoryStream(byteArrayIn))return Image.FromStream(mStream);//another easy way to convert image to bytearraypublicstaticbyte[]imgToByteConverter(Image inImg)ImageConverter imgCon =newImageConverter();return(byte[])imgCon.ConvertTo(inImg,typeof(byte[]));

Si tienes algún reparo o disposición de progresar nuestro crónica eres capaz de dejar una nota y con gusto lo estudiaremos.

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *