标签:
一,选取一张图片 var open = new OpenFileDialog(); open.Filter = "图片|*.jpg"; open.ShowDialog(); var filepath = open.FileName;
(1)将图片转成流,流的方式生成图片 //第一中方法,先转成流 FileStream file=new FileStream(filepath,FileMode.Open); //创建一个file.length大小的数组控件 byte[] bt= new byte[file.Length]; file.Read(bt, 0, bt.Length); file.Close();
//创建内存流 MemoryStream mstream=new MemoryStream(bt); System.Drawing.Image image = System.Drawing.Image.FromStream(mstream); var imgPath = "../../IMG/2015.png"; image.Save(imgPath, ImageFormat.Png);
(二)直接读取 System.Drawing.Image image = System.Drawing.Image.FromFile(filepath); var imgPath = "../../IMG/2015.png";
(3)转成位图进行存储 Bitmap bi=new Bitmap(filepath); var imgPath = "../../IMG/2015.png"; bi.Save(imgPath);
(4)先转成流,在使用位图进行读取 FileStream file = new FileStream(filepath, FileMode.Open); //创建一个file.length大小的数组控件 byte[] bt = new byte[file.Length]; file.Read(bt, 0, bt.Length); file.Close(); //把流转换成内存流 MemoryStream ms=new MemoryStream(bt); Bitmap bi = new Bitmap(ms); var imgPath = "../../IMG/2016.png"; bi.Save(imgPath,ImageFormat.Png);
标签:
原文地址:http://www.cnblogs.com/xiaoyaodijun/p/4516745.html