62,046
社区成员
发帖
与我相关
我的任务
分享
public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}
using (ZipFile zip = new ZipFile())
{
zip.AddEntry("aaa - Copy.EMB", File.ReadAllBytes("c:\\temp\\aaa - Copy.EMB"));
zip.AddEntry("GarbledCharacters.EMB", File.ReadAllBytes("c:\\temp\\GarbledCharacters.EMB"));
using (MemoryStream stream = new MemoryStream())
{
zip.Save(stream);
byte[] zipContent = stream.GetBuffer();
File.WriteAllBytes("MyZipFile.zip", zipContent);
}
}
上面例子把byte[]的内容加入到zip包中,最后的zip文件也保存到byte[]中。都是在内存中,不需要临时文件。