本文整理汇总了C#中Windows.Storage.StorageFile.GetThumbnailAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StorageFile.GetThumbnailAsync方法的具体用法?C# StorageFile.GetThumbnailAsync怎么用?C# StorageFile.GetThumbnailAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.StorageFile
的用法示例。
在下文中一共展示了StorageFile.GetThumbnailAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: fromStorageFile
// Fetches all the data for the specified file
public async static Task<FileItem> fromStorageFile(StorageFile f, CancellationToken ct)
{
FileItem item = new FileItem();
item.Filename = f.DisplayName;
// Block to make sure we only have one request outstanding
await gettingFileProperties.WaitAsync();
BasicProperties bp = null;
try
{
bp = await f.GetBasicPropertiesAsync().AsTask(ct);
}
catch (Exception) { }
finally
{
gettingFileProperties.Release();
}
ct.ThrowIfCancellationRequested();
item.Size = (int)bp.Size;
item.Key = f.FolderRelativeId;
StorageItemThumbnail thumb = await f.GetThumbnailAsync(ThumbnailMode.SingleItem).AsTask(ct);
ct.ThrowIfCancellationRequested();
BitmapImage img = new BitmapImage();
await img.SetSourceAsync(thumb).AsTask(ct);
item.ImageData = img;
return item;
}
示例2: Button_Click
private async void Button_Click(object sender, RoutedEventArgs e)
{
FolderPicker fp = new FolderPicker();
fp.FileTypeFilter.Add("*");
fp.SuggestedStartLocation = PickerLocationId.Desktop;
fp.ViewMode = PickerViewMode.Thumbnail;
var files = await fp.PickSingleFolderAsync();
iol = await files.GetFilesAsync();
//IReadOnlyList<StorageFolder> file = iol
Myobj myobj = new Myobj();
ObservableCollection<Myobj> datasource = new ObservableCollection<Myobj>();
//Windows.Storage.Streams.IRandomAccessStream iras = await sf.OpenAsync(FileAccessMode.Read);
sf = iol[0];
//IReadOnlyList<IStorageFile> file = ;
foreach (StorageFile a in iol)
{
myobj.Name = sf.DisplayName.ToString();
//gw.DisplayMemberPath = "Name";
var tn = await sf.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.PicturesView);
BitmapImage bi = new BitmapImage();
bi.SetSource(tn);
myobj.Thumbnail = bi;
datasource.Add(myobj);
}
this.gw.ItemsSource = datasource;
// gw.DisplayMemberPath = "data";
}
示例3: GetThumbnailForFile
private async Task<StorageItemThumbnail> GetThumbnailForFile(StorageFile file)
{
try
{
return await file.GetThumbnailAsync(ThumbnailMode.ListView, 120);
}
catch
{
}
var assetsFolder = await Package.Current.InstalledLocation.GetFolderAsync("Assets");
StorageFile iconFile = null;
try
{
iconFile = await assetsFolder.GetFileAsync(string.Format("{0}-icon.png", file.FileType.Trim('.')));
}
catch
{
}
if (iconFile == null)
{
iconFile = await assetsFolder.GetFileAsync("generic-icon.png");
}
return await iconFile.GetThumbnailAsync(ThumbnailMode.ListView, 120);
}
示例4: ThumbnailPhoto
private async Task ThumbnailPhoto(ExplorerItem item, StorageFile sf, bool file = false)
{
if (item == null && item.Image != null) return;
StorageItemThumbnail fileThumbnail = await sf.GetThumbnailAsync(ThumbnailMode.SingleItem, 250);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(fileThumbnail);
if (file == false)
item.Image = bitmapImage;
else
item.Image = bitmapImage;
}
示例5: ReportPhoto
public ReportPhoto(StorageFile file)
{
FilePath = file.Path;
StorageItemThumbnail thumbnail = file.GetThumbnailAsync(ThumbnailMode.ListView).AsTask().Result;
BitmapImage thumbnailImage = new BitmapImage();
var ignore = thumbnailImage.SetSourceAsync(thumbnail);
ThumbnailSource = thumbnailImage;
StorageItemThumbnail imageAsThumbnail = file.GetScaledImageAsThumbnailAsync(ThumbnailMode.SingleItem).AsTask().Result;
WriteableBitmap bitmap = new WriteableBitmap((int)imageAsThumbnail.OriginalWidth, (int)imageAsThumbnail.OriginalHeight);
ignore = bitmap.SetSourceAsync(imageAsThumbnail);
Bitmap = bitmap;
}
示例6: GetThumbnail
public async Task<StorageItemThumbnail> GetThumbnail(StorageFile file)
{
StorageItemThumbnail thumb = null;
try
{
thumb = await file.GetThumbnailAsync(ThumbnailMode.VideosView);
}
catch (Exception ex)
{
LogHelper.Log("Error getting thumbnail: ");
LogHelper.Log(ex);
}
return thumb;
}
示例7: affectBitmapImageToNewDisplayablePhotoObject
private static async Task affectBitmapImageToNewDisplayablePhotoObject(StorageFile file, VideoDataStructure pds)
{
StorageItemThumbnail fileThumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 900);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(fileThumbnail);
pds.Image = bitmapImage;
}
示例8: fillBackgroundImage
private async void fillBackgroundImage(LifeMapStructure lifeMap, StorageFile storageFile)
{
Utils.Constants.StartLoadingAnimation(MainGrid);
if (lifeMap.ImagePath != "")
{
try
{
StorageFile sf = await Windows.Storage.StorageFile.GetFileFromPathAsync(storageFile.Path);
StorageItemThumbnail fileThumbnail = await storageFile.GetThumbnailAsync(ThumbnailMode.SingleItem, 800);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(fileThumbnail);
lifeMap.Image = bitmapImage;
await Utils.FilesSaver<LifeMapStructure>.SaveData(Data.LifeMapMgr.LifeMaps, Constants.NamingListLifeMaps);
Helper.CreateToastNotifications(Constants.ResourceLoader.GetString("UpdatedLiftMapBackground"));
}
catch
{
lifeMap.ImagePath = "";
Utils.Constants.ShowWarningDialog(Constants.ResourceLoader.GetString("2cannotreadfile") + " : " + storageFile.Path + "\n\r" +
Constants.ResourceLoader.GetString("2possiblereasondocumentlibararycannotaccess"));
}
}
else
{
await fillBackgroundImageNonLocal(lifeMap, storageFile);
}
Utils.Constants.StopLoadingAnimation(MainGrid);
}
示例9: FillFileProperties
public async static Task FillFileProperties(IFileProperties fileProps, StorageFile file, StorageFolder topFolder, string fileSubPath, BasicProperties basicProps)
{
try
{
fileProps.FileName = file.Name;
fileProps.AbsolutePath = file.Path;
fileProps.SelectedFolder = Util.FolderPath(topFolder);
if (!string.IsNullOrEmpty(fileSubPath))
fileProps.ContainingFolder = fileSubPath;
else
fileProps.ContainingFolder = ""; //fileProps.HideContainingFolder();
string ftype = GetFileTypeText(file, false);
if (!string.IsNullOrEmpty(ftype))
fileProps.FileType = ftype;
else
fileProps.HideFileType();
if (basicProps != null)
fileProps.FileSize = Util.SizeToString(basicProps.Size, "B");
else
fileProps.HideFileSize();
if (!string.IsNullOrEmpty(file.Provider.DisplayName))
{
string flocation = file.Provider.DisplayName;
if (!string.IsNullOrEmpty(file.Provider.Id) && file.Provider.DisplayName.IndexOf(file.Provider.Id, StringComparison.OrdinalIgnoreCase) <= -1)
flocation += " (" + file.Provider.Id.Substring(0, 1).ToUpper() + file.Provider.Id.Substring(1) + ") ";
fileProps.FileLocation = flocation;
}
else if (!string.IsNullOrEmpty(file.Provider.Id))
fileProps.FileLocation = file.Provider.Id;
else
fileProps.HideFileLocation();
StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.DocumentsView, 260, ThumbnailOptions.None);
Image image = Util.GetImage(thumbnail);
if (image != null)
fileProps.FileImage = image.Source;
}
catch (Exception ex) { Debug.WriteLine(ex.ToString()); }
}
示例10: AddThumbnail
public async void AddThumbnail(StorageFile file, VideoDataItem item) {
StorageItemThumbnail thumb = await file.GetThumbnailAsync(ThumbnailMode.VideosView);
if(thumb != null) {
BitmapImage img = new BitmapImage();
await img.SetSourceAsync(thumb);
item.Image = img; } }
示例11: setAlbumProfileImage
private async Task setAlbumProfileImage(DataModel.LifeMapStructure lifeMap, StorageFile file)
{
StorageItemThumbnail fileThumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 700);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(fileThumbnail);
lifeMap.Image = bitmapImage;
}
示例12: GetThumbnailFromStorageFile
public static async Task<BitmapImage> GetThumbnailFromStorageFile(StorageFile file)
{
ThumbnailMode thumbnailMode = ThumbnailMode.ListView;
ThumbnailOptions thumbnailOptions = ThumbnailOptions.UseCurrentScale;
BitmapImage bitmapThumbnail = new BitmapImage();
StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(thumbnailMode, ThumbnailSize, thumbnailOptions);
if (thumbnail != null)
{
bitmapThumbnail.SetSource(thumbnail);
return bitmapThumbnail;
}
else
{
return null;
}
}
示例13: albumart
public async void albumart(StorageFile fil)
{
using (StorageItemThumbnail storageItemThumbnail = await fil.GetThumbnailAsync(ThumbnailMode.SingleItem, 200, ThumbnailOptions.ResizeThumbnail))
using (IInputStream inputStreamAt = storageItemThumbnail.GetInputStreamAt(0))
using (var dataReader = new DataReader(inputStreamAt))
{
uint u = await dataReader.LoadAsync((uint)storageItemThumbnail.Size);
IBuffer readBuffer = dataReader.ReadBuffer(u);
var tempFolder = ApplicationData.Current.RoamingFolder;
try
{
var imageFile = await tempFolder.CreateFileAsync(fil.DisplayName + ".png", CreationCollisionOption.OpenIfExists);
using (IRandomAccessStream randomAccessStream = await imageFile.OpenAsync(FileAccessMode.ReadWrite))
using (IOutputStream outputStreamAt = randomAccessStream.GetOutputStreamAt(0))
{
await outputStreamAt.WriteAsync(readBuffer);
await outputStreamAt.FlushAsync();
}
}
catch
{
// ErrorCorrecting("013");
}
}
}
示例14: affectBitmapImageToNewDisplayablePhotoObject
private static async Task affectBitmapImageToNewDisplayablePhotoObject(StorageFile file, PhotoDataStructure pds)
{
try
{
if(file == null || pds == null) return;
StorageItemThumbnail fileThumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 600);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(fileThumbnail);
pds.Image = bitmapImage;
}
catch(Exception exp)
{
throw exp;
}
}
示例15: setAlbumProfileImage
private static async Task<bool> setAlbumProfileImage(DataModel.AlbumDataStructure item, StorageFile file)
{
try
{
StorageItemThumbnail fileThumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 400);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(fileThumbnail);
item.ImagePath = bitmapImage;
return true;
}
catch
{
return false;
}
}