(1)将a.jpg文件转换成二进制数组,并放入到arrbyte数组中。
FileStream fs = new FileStream(@"F:\a.jpg", FileMode.Open, FileAccess.Read); byte[] arrbyte=new byte[fs.Length]; fs.Read(arrbyte, 0, arrbyte.Length); fs.Close();
(2)改变图片大小,使用Bitmap类改变图片为宽40高50,并放入到二进制数组中。
Image img = new Bitmap(Image.FromStream(new MemoryStream((byte[])arrbyte)),40,50); //Image img1=new Bitmap(Image.FromFile(@"F:\a.jpg"),40,50); MemoryStream ms = new MemoryStream(); img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] arrbyte1= ms.GetBuffer();
(3)将二进制数组 arrbyte转化为Image;
Image readimg = Image.FromStream(new MemoryStream((byte[])arrbyte)); pictureBox1.Image = readimg;
转自:http://xuehaiboisme.blog.163.com/blog/static/8414282920105255026495/