image to byte array online and display in html c# code example
Example: 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 img = Image.FromFile("d:\\bank-copy.png");
byte[] bArr = imgToByteArray(img);
Image img1 = byteArrayToImage(bArr);
pictureBox1.Image = img1;
}
public byte[] imgToByteArray(Image img)
{
using (MemoryStream mStream = new MemoryStream())
{
img.Save(mStream, img.RawFormat);
return mStream.ToArray();
}
}
public Image byteArrayToImage(byte[] byteArrayIn)
{
using (MemoryStream mStream = new MemoryStream(byteArrayIn))
{
return Image.FromStream(mStream);
}
}
public static byte[] imgToByteConverter(Image inImg)
{
ImageConverter imgCon = new ImageConverter();
return (byte[])imgCon.ConvertTo(inImg, typeof(byte[]));
}
}
}