#region//图片转换为二进制流 public void PictureToBinaryStream() {
string path = Application.StartupPath; string fullPath = path + "\\images\\test.png"; Bitmap bmp =
new Bitmap(Image.FromFile(fullPath)); MemoryStream ms =
new MemoryStream(); bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png); ms.Flush();
byte[] bmpBytes = ms.ToArray(); foreach (var item in bmpBytes) { richTextBox1.Text += item; } pictureBox1.Image = Image.FromStream(
new MemoryStream(bmpBytes)); }
#endregion #region//二进制流转换成图片 public void BinaryStreamToPicture() {
string url = @"http://php.weather.sina.com.cn/images/yb3/78_78/duoyun_0.png"; WebClient client =
new WebClient(); byte[] pageData = client.DownloadData(url); pictureBox1.Image = Image.FromStream(
new MemoryStream(pageData)); Bitmap bmp =
new Bitmap(new MemoryStream(pageData)); string path = Application.StartupPath; string fullPath = path + "\\images\\"+ Guid.NewGuid().ToString()+".png"; richTextBox1.Text = fullPath; bmp.Save(fullPath, System.Drawing.Imaging.ImageFormat.Png); }
#endregion
转载于:https://www.cnblogs.com/jimmyLei/p/9037892.html
相关资源:二进制流与图片的相互转换