图片能转成2进制的代码吗?

图片能转成2进制的代码吗?
有的图片单张就3.4兆, 能把这些图片转成2进制代码存起来吗?
这么不就能小很多吗?
转成2进制以后,
图片还会这么大吗?
图片质量会不会有损失?
可以转的,可以把图片序列化哼二进字节数组,也可以把二进制字节数组反序列化为图片。使用BinaryFormatter类来操作,图片质量不会有损失。 给你个示例。

///
/// 把对象序列化并返回相应的字毁中节
///

/// 需要序列化的对象
//纤散山/ byte[]
public byte[] SerializeObject(object pObj)
{
if (pObj == null)
return null;
System.IO.MemoryStream _memory = new System.IO.MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(_memory, pObj);
_memory.Position = 0;
byte[] read = new byte[_memory.Length];
_memory.Read(read, 0, read.Length);
_memory.Close();
return read;
}
///
/// 把字节反序列化成相应的对象
///

/// <掘昌param name="pBytes">字节流
/// object
public object DeserializeObject(byte[] pBytes)
{
object _newOjb = null;
if (pBytes == null)
return _newOjb;
System.IO.MemoryStream _memory = new System.IO.MemoryStream(pBytes);
_memory.Position = 0;
BinaryFormatter formatter = new BinaryFormatter();
_newOjb = formatter.Deserialize(_memory);
_memory.Close();
return _newOjb;
}
任何数据存储在电脑上时都是以2进制来存储的。。。。
← 上一篇: 下一篇: →