c# image to byte array
public byte[] ImageToByteArray(System.Drawing.Image imageIn)
{
using (var ms = new MemoryStream())
{
imageIn.Save(ms,imageIn.RawFormat);
return ms.ToArray();
}
}
c# image to byte array
public byte[] ImageToByteArray(System.Drawing.Image imageIn)
{
using (var ms = new MemoryStream())
{
imageIn.Save(ms,imageIn.RawFormat);
return ms.ToArray();
}
}
Image to byte array C#
using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//image to byteArray
Image img = Image.FromFile("d:\\bank-copy.png");
byte[] bArr = imgToByteArray(img);
//byte[] bArr = imgToByteConverter(img);
//Again convert byteArray to image and displayed in a picturebox
Image img1 = byteArrayToImage(bArr);
pictureBox1.Image = img1;
}
//convert image to bytearray
public byte[] imgToByteArray(Image img)
{
using (MemoryStream mStream = new MemoryStream())
{
img.Save(mStream, img.RawFormat);
return mStream.ToArray();
}
}
//convert bytearray to image
public Image byteArrayToImage(byte[] byteArrayIn)
{
using (MemoryStream mStream = new MemoryStream(byteArrayIn))
{
return Image.FromStream(mStream);
}
}
//another easy way to convert image to bytearray
public static byte[] imgToByteConverter(Image inImg)
{
ImageConverter imgCon = new ImageConverter();
return (byte[])imgCon.ConvertTo(inImg, typeof(byte[]));
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us