码迷,mamicode.com
首页 > 其他好文 > 详细

图片和流的相互转化 (c/s)

时间:2014-05-01 15:35:40      阅读:315      评论:0      收藏:0      [点我收藏+]

标签:blog   class   code   ext   int   string   文件   line   com   har   name   

//图片转化为流保存;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Stream ms;
               byte[] picbyte;
               OpenFileDialog open = new OpenFileDialog();
 
               open.Filter = "图片文件(*.jpg)|*.jpg|图片文件(*.png)|*.png|图片文件(*.bmp)|*.bmp|图片文件(*.jpeg)|*.jpeg";
 
               open.RestoreDirectory = true;
 
               if (open.ShowDialog() == DialogResult.OK)
               {
                   if ((ms = open.OpenFile()) != null)
                   {
                       picbyte = new byte[ms.Length];
                       ms.Position = 0;
                       ms.Read(picbyte, 0, Convert.ToInt32(ms.Length));
                       // 图片
                       model_BD010.BD010_008 = picbyte;
                       ms.Close();
                   }
               }
               string path = open.FileName;
               txtUserImg.Text = path;
               // 显示预览图片
               picUser.Image = Image.FromFile(path);

 

 

 //流转化为图片

picPhoto.Image = Image.FromStream(new MemoryStream((byte[])str));

图片和流的相互转化 (c/s),码迷,mamicode.com

图片和流的相互转化 (c/s)

标签:blog   class   code   ext   int   string   文件   line   com   har   name   

原文地址:http://www.cnblogs.com/wlzhang/p/3700807.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!