I want to add a set of images to a ZIP file in C#. I use EmguCV to save the images. Currently I save the image locally first and then add to ZIP as follows.
Is there anyway to add the images to ZIP file directly on the fly without saving locally?
Sorry if this is a duplicate, I could not locate a clear answer for days.
using (FileStream zipToOpen = new FileStream(this.path, FileMode.Create))
{
using (ZipArchive zipArchive = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
{
for (int i = 0; i < clouds.Count; i++)
{
string imageCname = kinectId + "_" + dateTimes[i] + ".jpg";
imageCt = imageCs[i];
imageCt.Save("imageCt.jpg");
zipArchive.CreateEntryFromFile(@"imageCt.jpg", imageCname);
Console.WriteLine("Flushing rgb " + i + " of " + clouds.Count);
}
}
}
Update 1:
As suggested by #CarbineCoder I edited the code as follows. It saves a file. But cannot open as an image. I guess, it just save only the Byte steam. What else may I do to save it as a jpeg image.
string imageCname = kinectId + "_" + dateTimes[i] + ".jpg";
imageCt = imageCs[i];
ZipArchiveEntry zipEntryC = zipArchive.CreateEntry(imageCname);
using (var originalFileStream = new MemoryStream(imageCt.Bytes))
{
using (var zipEntryStream = zipEntryC.Open())
{
originalFileStream.CopyTo(zipEntryStream);
}
}