仍在我的幻灯片项目中工作!不太破旧,它现在可以递归读取目录,按顺序或随机顺序显示文件,放大和缩小,响应键盘和鼠标输入。
我现在正试图使其读取zip文件的内容而不将其解压缩。当我递归读取用户提供的根目录作为输入时,它会将遇到的所有文件存储为StorageFile对象的列表。我希望能够读取zip文件的内容并将其文件(即图像)添加到StorageFile列表中,然后最终打开并提取单个给定的文件(如果它是按顺序或随机顺序的下一个文件)。
到目前为止,我发现的内容允许提取磁盘上的文件或读取zip文件的内容作为字符串列表。
我清楚我需要什么吗?知道怎么做吗?
谢谢! :)
答案 0 :(得分:0)
好吧,我可以打开zip文件,读取它们的ZipArchiveEntry内容,并在ZipArchiveEntries的内存中创建一个列表。但是,我遇到的问题有两点:
1)如何重新打开ZipArchive并访问列表中的特定ZipArchiveEntry?
2)如何将作为.jpg图像的ZipArchiveEntry读取到BitmapImage中,以将其显示在Image.Source中?
这是一个代码示例,它无法正常工作!大声笑!
public class ZipItem
{
public StorageFile motherfile { get; set; } //Source File
public ZipArchiveEntry motherentry { get; set; } /Compressed file within the source file
public string Name { get; set; }
public string ActualBytes { get; set; }
public string CompressedBytes { get; set; }
}
public List<ZipItem> results; //List of all ZipItems (all elements of a Zipfile, for manipulation purposes)
public int numfiles = 0; // Total number of files
public int i = 0; //Pointer to the current element in the list (for slideshow purposes)
private async void nextimg_Click(object sender, RoutedEventArgs e)
{
Stream stream = await results[i].motherfile.OpenStreamForReadAsync(); //Create a stream... I know this is the wrong type (see error below)
ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Update); //Open the ZipArchive. This gives me an error telling me that "Update mode requires a stream with Read, Write and Seek permission.
ZipArchiveEntry entry = results[i].motherentry; //This is where I'm stuck.... how do I tell it to open a specific entry in the zip file?
using (var fileStream = entry.Open()) //How do I open it as an IRandomAccessStream?
//using (IRandomAccessStream fileStream = results[i].motherentry.Open());
{
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.DecodePixelHeight = (int)ctlImage.Height;
bitmapImage.DecodePixelWidth = (int)ctlImage.Width;
bitmapImage.SetSource(filestream); //I know I need a IRandomAccessStream
ctlImage.Source = bitmapImage; //Hopefully display the image...
}
}