【问题标题】:Turn byte[] to .jpeg and zip将 byte[] 转换为 .jpeg 和 zip
【发布时间】:2015-10-21 15:36:27
【问题描述】:

我需要编写一个方法将 byte[] 转换为 .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;
}

【问题讨论】:

  • 先搜索一个步骤,然后搜索另一个步骤。
  • byte[] 里面是什么?还要确保您的代码不起作用。没有魔法。看看这里stackoverflow.com/questions/8946846/… 也压缩文件只是谷歌它。 stackoverflow.com/questions/940582/…
  • 感谢您的帮助。我读过的关于 zip 文件的在线帖子大多是使用文件系统来压缩文件,这不是我想要的。我希望在不使用文件系统的情况下将带有 jpeg 文件的 zip 文件返回给用户。

标签: c# asp.net


【解决方案1】:

既然你已经有了你的字节数组,那么你距离将它转换为 jpeg 仅一步之遥!

using(Image image = Image.FromStream(new MemoryStream(bitmap)))
{
    image.Save("output.jpg", ImageFormat.Jpeg);  
}

Image.FromStream()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-11
    • 2011-06-08
    • 2015-08-17
    • 2014-07-21
    • 1970-01-01
    • 1970-01-01
    • 2011-10-28
    • 1970-01-01
    相关资源
    最近更新 更多