将byte[]转换为.jpeg和zip
本文关键字:jpeg zip 转换 byte | 更新日期: 2023-09-27 18:18:30
我需要写一个方法把字节[]转换成。jpeg文件,然后压缩这些jpeg文件。
我做了一些调查,但仍然没有弄清楚。谢谢你的帮助。
<标题> 代码更新Using Ionic.Zip;
public static void ZipJpeg(int ID)
{
ZipFile zip = new ZipFile();
Dictionary<int, byte[]> photos = new Dictionary<int, byte[]>();
photos = clientInfo_BL.GetByID(ID);
string fileName;
foreach(var p in photos.Values)
{
fileName = p.uploadDate.toString() + ".jpeg";
using(Image image = image.FromStream(new MemoryStream(p.ImageData)))
{
image.Save(fileName. ImageFormat.Jpeg);
}
Zip.AddEntry(image); // couldnt figure out this one
}
zip.save()//not sure if this one is right
return zip;
}
标题>
既然您已经有了字节数组,那么您只需一步就可以将其转换为jpeg!
using(Image image = Image.FromStream(new MemoryStream(bitmap)))
{
image.Save("output.jpg", ImageFormat.Jpeg);
}
Image.FromStream ()