Image _Image = Image.FromFile(fileName); MemoryStream stream = new MemoryStream(); _Image.Save(stream, ImageFormat.Bmp); byte[] _ImageBytes = stream.GetBuffer(); return _ImageBytes; byte[] bytes = null; using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { using (BinaryReader br = new BinaryReader(fs)) { bytes = br.ReadBytes((int)fs.Length); } } return bytes;
这2段代码都是将图片转成byte[],为什么转出来的内容会不一样?
发现将 MemoryStream 的方法改成这个:stream.Read(_ImageBytes, 0, Convert.ToInt32( stream.Length));2种方法就一样了.
stream.GetBuffer();stream.Read()这2个方法有什么不一样的吗
http://msdn.microsoft.com/zh-cn/library/system.io.memorystream.getbuffer.aspx
GetBuff返回从其创建此流的无符号字节数组。
而stream.Read() BUFF是什么样就返回什么样