namespace 图片的二进制转化
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
byte[] data = SetImageToByteArray(pictureBox1.Image);
for(int i=0;i<data.Length;i++)
{
textBox1.Text = data[i].ToString();
}
}
public byte[] SetImageToByteArray(Image image)
{
if (image == null) { return null; }
byte[] data = null;
using (MemoryStream ms = new MemoryStream())
{
using (Bitmap Bitmap = new Bitmap(image))
{
Bitmap.Save(ms, MemoryBmp);
ms.Position = 0;
data = new byte[ms.Length];
ms.Read(data, 0, Convert.ToInt32(ms.Length));
ms.Flush();
}
}
return data;
}
public System.Drawing.Imaging.ImageFormat MemoryBmp { get; set; }
}
}
|
|