/// <summary> /// アーカイブファイルからサムネイル用画像データを取得する /// </summary> /// <param name="path"></param> /// <param name="thumWidth"></param> /// <returns></returns> public static async Task <BitmapImage> GetFirstImageFromArchive(string path, int thumWidth) { BitmapImage bitmap = null; StorageFile zipFile = await StorageFile.GetFileFromPathAsync(path); using (IRandomAccessStream randomStream = await zipFile.OpenReadAsync()) { using (Stream stream = randomStream.AsStreamForRead()) { using (ZipArchive zipArchive = new ZipArchive(stream)) { foreach (ZipArchiveEntry entry in zipArchive.Entries) { if (FileKind.IsImageFile(entry.FullName)) { bitmap = await BitmapUtils.CreateBitmap(entry, thumWidth); break; } } } } } return(bitmap); }
/// <summary> /// ZIPデータを読み込みファイル一覧を作成する /// </summary> /// <returns></returns> public async Task LoadDataAsync() { this.Dispose(); this.m_dataList.Clear(); StorageFile zipFile = await StorageFile.GetFileFromPathAsync(m_imageParam.Path); StorageHistoryManager.AddStorage(zipFile, StorageHistoryManager.DataType.Latest); this.ParentStorage = zipFile; IRandomAccessStream randomStream = await zipFile.OpenReadAsync(); Stream stream = randomStream.AsStreamForRead(); m_zipArchive = new ZipArchive(stream); foreach (ZipArchiveEntry entry in m_zipArchive.Entries) { if (FileKind.IsImageFile(entry.FullName)) { m_dataList.Add(entry); } } sortList(m_dataList); //名前の順に並び替え foreach (ZipArchiveEntry entry in m_dataList) { Debug.WriteLine(entry.Name); } }
public static async Task <BitmapImage> CreateBitmapFromArchiveCover(string path, int thumWidth) { StorageFolder folder = await EnvPath.GetArchiveCoverFolder(); string fileName = EnvPath.GetArchiveCoverFileName(path); IStorageItem imageFile = await folder.TryGetItemAsync(fileName); if (imageFile == null) { using (await m_asyncLock.LockAsync()) { StorageFile coverFile = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); StorageFile zipFile = await StorageFile.GetFileFromPathAsync(path); using (IRandomAccessStream randomStream = await zipFile.OpenReadAsync()) { using (Stream stream = randomStream.AsStreamForRead()) { using (ZipArchive zipArchive = new ZipArchive(stream)) { foreach (ZipArchiveEntry entry in zipArchive.Entries) { if (FileKind.IsImageFile(entry.FullName)) { /* * WriteableBitmap writeableBitmap = await createWriteableBitmap(entry); * await saveToJpegFile(writeableBitmap, coverFile); * imageFile = await folder.GetFileAsync(fileName); */ imageFile = await SaveToFileFromZipEntry(entry, coverFile); break; } } } } } } } if (imageFile != null) { return(await CreateThumbnailBitmap(imageFile, (uint)thumWidth)); } else { return(null); } }