日期:2014-05-17 浏览次数:20755 次
FileStream fs = new FileStream(path, FileMode.Open); byte[] data = new byte[fs.Length]; fs.Read(data, 0, data.Length); fs.Close(); MemoryStream ms = new MemoryStream(data);
------解决方案--------------------
///定义并实例化一个内存流,以存放图片的字节数组。
MemoryStream m = new MemoryStream();
///获得当前路径
string strAppPath = AppDomain.CurrentDomain.BaseDirectory; //获得可执行文件的路径。
///获得图片路径
string strPath = strAppPath + "img\\default.jpg";
///图片读入FileStream
FileStream f = new FileStream(strPath, FileMode.open);
///把FileStream写入MemoryStream
m.SetLength(f.Length);
f.Read(m.GetBuffer(), 0, (int)f.Length);
m.Flush();
f.Close();
------解决方案--------------------
FileStream fs = new FileStream(fileName, FileMode.Open); byte[] MyData = new byte[fs.Length]; fs.Read(MyData, 0, (int)fs.Length); fs.Close(); MemoryStream ms = new MemoryStream(MyData);
------解决方案--------------------
MemoryStream ms = new MemoryStream(File.ReadAllBytes("c:\\1.jpg"));