从zip文件中读取Image对象中的图像文件

时间:2012-11-03 11:43:25

标签: c# winforms zip

我正在使用iconic.dll文件从压缩文件中读取数据(.zip文件扩展名)

请检查下面的代码

string zippath = txtFilePath.Text.Trim() + "\\" + foldername + ".zip";
ArrayList arrFiles = new ArrayList();
using (ZipFile zip = ZipFile.Read(enrollment))
{
     foreach (ZipEntry e1 in zip)
     {
       arrFiles.Add(e1.ToString());
     }
}

foreach (string path in arrFiles)
{
   Image img1 = Image.FromFile(path);  //geting error on this line
   imageList.Images.Add(getThumbnaiImage(imageList.ImageSize.Width, img1));
}

如何从压缩文件夹中读取图像文件?

2 个答案:

答案 0 :(得分:1)

这似乎是解决方案:

  using (ZipFile zip = ZipFile.Read(enrollment))
        {

            foreach (ZipEntry e1 in zip)
            {

                    CrcCalculatorStream reader = e1.OpenReader();
                    MemoryStream memstream = new MemoryStream();
                    reader.CopyTo(memstream);
                    byte[] bytes = memstream.ToArray();
                    Image img1 = Image.FromStream(memstream);
                    imageList.Images.Add(getThumbnaiImage(imageList.ImageSize.Width, img1));


            }
        }

答案 1 :(得分:0)

试试这个:

  using (ZipFile zip = ZipFile.Read(enrollment))
{
    ZipEntry entry = zip["Image.bmp"];
    entry.Extract(outputStream);
}

您还可以在pricturebox中显示图像:

PictureBox pb = new PictureBox();
        pb.Location = new Point(100, 100);
        pb.SizeMode = PictureBoxSizeMode.Zoom;
        var bmp = new Bitmap(outputStream);
        pb.Image = bmp;
        this.Controls.Add(pb);