- #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
posted @
2018-05-14 20:07
LieJimmy
阅读(
835)
评论()
编辑
收藏
举报