日期:2014-05-20 浏览次数:20897 次
System.IO.MemoryStream ms = new System.IO.MemoryStream();
this._image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] bytes = new byte[] { };
bytes = ms.GetBuffer();
outStream.writeByteArray(bytes);
//上面是转换为byte数组,下面这段是写入文件:
public void writeByteArray(byte[] bytes)
{
long length = bytes.Length;
byte[] tbs = BitConverter.GetBytes(length);
for (int i = 0; i < tbs.Length; i++)
{
writer.Write(tbs[i]);
}
for (int i = 0; i < bytes.Length; i++)
{
writer.Write(bytes[i]);
}
}
public byte[] readBytesArray()
{
ulong temp = 0;
ulong length = (ulong)BitConverter.GetBytes(temp).Length;
byte[] byLen = new byte[length];
for (ulong i = 0; i < length; i++)
{
byLen[i] = cacheBuff[this.position++];
}
length = BitConverter.ToUInt64(byLen, 0);
byte[] bytes = new byte[length];
for (ulong i = 0; i < length; i++)
{
bytes[i] = cacheBuff[this.position++];