下面的例子是从zip压缩文件解压出jpg文件流,再显示出来。

StorageFile zip = await KnownFolders.PicturesLibrary.GetFileAsync("1.zip");

using (ZipArchive archive = new ZipArchive((await zip.OpenAsync(FileAccessMode.ReadWrite)).AsStream(), ZipArchiveMode.Update))       
{
        InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream();
        using (var stream = archive.GetEntry("1.jpg").Open())
       {
            await stream.CopyToAsync(ras.AsStreamForWrite()); //Stream转成IRandomAccessStream
            await ras.FlushAsync();
            ras.Seek(); //这句是关键,必须把流的起点重新设置
            BitmapImage bi = new BitmapImage();
            bi.SetSource(ras);
            img.Source = bi; } }
05-11 13:02