演示如何获取文件的缩略图

FileSystem/ThumbnailAccess.xaml

<Page
x:Class="XamlDemo.FileSystem.ThumbnailAccess"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:XamlDemo.FileSystem"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<ScrollViewer Margin="120 0 0 0">
<StackPanel> <Button Name="btnGetThumbnail" Content="获取文件的缩略图" Click="btnGetThumbnail_Click_1" /> <Image Name="img" Stretch="None" HorizontalAlignment="Left" Margin="0 10 0 0" />
<TextBlock Name="lblMsg" FontSize="14.667" Margin="0 10 0 0" /> </StackPanel>
</ScrollViewer>
</Grid>
</Page>

FileSystem/ThumbnailAccess.xaml.cs

/*
* 演示如何获取文件的缩略图
*
* 获取指定文件或文件夹的缩略图,返回 StorageItemThumbnail 类型的数据
* StorageFile.GetThumbnailAsync(ThumbnailMode mode, uint requestedSize, ThumbnailOptions options)
* StorageFolder.GetThumbnailAsync(ThumbnailMode mode, uint requestedSize, ThumbnailOptions options)
* ThumbnailMode mode - 用于描述缩略图的目的,以使系统确定缩略图图像的调整方式(PicturesView, VideosView, MusicView, DocumentsView, ListView, SingleItem)
* 关于 ThumbnailMode 的详细介绍参见:http://msdn.microsoft.com/en-us/library/windows/apps/hh465350.aspx
* uint requestedSize - 期望尺寸的最长边长的大小
* ThumbnailOptions options - 检索和调整缩略图的行为(None, ReturnOnlyIfCached, ResizeThumbnail, UseCurrentScale)
*/ using System;
using Windows.Storage;
using Windows.Storage.FileProperties;
using Windows.Storage.Pickers;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging; namespace XamlDemo.FileSystem
{
public sealed partial class ThumbnailAccess : Page
{
public ThumbnailAccess()
{
this.InitializeComponent();
} private async void btnGetThumbnail_Click_1(object sender, RoutedEventArgs e)
{
if (XamlDemo.Common.Helper.EnsureUnsnapped())
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.FileTypeFilter.Add("*"); StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
ThumbnailMode thumbnailMode = ThumbnailMode.PicturesView;
ThumbnailOptions thumbnailOptions = ThumbnailOptions.UseCurrentScale;
uint requestedSize = 200; using (StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(thumbnailMode, requestedSize, thumbnailOptions))
{
if (thumbnail != null)
{
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(thumbnail);
img.Source = bitmapImage; lblMsg.Text = "file name: " + file.Name;
lblMsg.Text += Environment.NewLine;
lblMsg.Text += "requested size: " + requestedSize;
lblMsg.Text += Environment.NewLine;
lblMsg.Text += "returned size: " + thumbnail.OriginalWidth + "*" + thumbnail.OriginalHeight;
}
}
}
}
}
}
}

4、演示如何通过 AQS - Advanced Query Syntax 搜索本地文件

FileSystem/AQS.xaml.cs

 
 
/*
* 演示如何通过 AQS - Advanced Query Syntax 搜索本地文件
*/ using System;
using System.Collections.Generic;
using Windows.Storage;
using Windows.Storage.BulkAccess;
using Windows.Storage.FileProperties;
using Windows.Storage.Search;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation; namespace XamlDemo.FileSystem
{
public sealed partial class AQS : Page
{
public AQS()
{
this.InitializeComponent();
} protected async override void OnNavigatedTo(NavigationEventArgs e)
{
// 准备在“音乐库”中进行搜索(需要在 Package.appxmanifest 的“功能”中选中“音乐库”)
StorageFolder musicFolder = KnownFolders.MusicLibrary; // 准备搜索所有类型的文件
List<string> fileTypeFilter = new List<string>();
fileTypeFilter.Add("*"); // 搜索的查询参数
QueryOptions queryOptions = new QueryOptions(CommonFileQuery.OrderByDate, fileTypeFilter);
// 指定 AQS 字符串,参见 http://msdn.microsoft.com/zh-cn/library/windows/apps/aa965711.aspx
queryOptions.UserSearchFilter = "五月天"; // 根据指定的参数创建一个查询
StorageFileQueryResult fileQuery = musicFolder.CreateFileQueryWithOptions(queryOptions); lblMsg.Text = "在音乐库中搜索“五月天”,结果如下:";
lblMsg.Text += Environment.NewLine; // 开始搜索,并返回检索到的文件列表
IReadOnlyList<StorageFile> files = await fileQuery.GetFilesAsync(); if (files.Count == 0)
{
lblMsg.Text += "什么都没搜到";
}
else
{
foreach (StorageFile file in files)
{
lblMsg.Text += file.Name;
lblMsg.Text += Environment.NewLine;
}
} // 关于 QueryOptions 的一些用法,更详细的 QueryOptions 的说明请参见 msdn
queryOptions = new QueryOptions();
queryOptions.FolderDepth = FolderDepth.Deep;
queryOptions.IndexerOption = IndexerOption.UseIndexerWhenAvailable;
queryOptions.SortOrder.Clear();
var sortEntry = new SortEntry();
sortEntry.PropertyName = "System.FileName";
sortEntry.AscendingOrder = true;
queryOptions.SortOrder.Add(sortEntry); fileQuery = KnownFolders.PicturesLibrary.CreateFileQueryWithOptions(queryOptions);
}
}
}
 
 

获取文件的缩略图Thumbnail和通过 AQS - Advanced Query Syntax 搜索本地文件的更多相关文章

  1. 重新想象 Windows 8 Store Apps (22) - 文件系统: 访问文件夹和文件, 通过 AQS 搜索本地文件

    原文:重新想象 Windows 8 Store Apps (22) - 文件系统: 访问文件夹和文件, 通过 AQS 搜索本地文件 [源码下载] 重新想象 Windows 8 Store Apps ( ...

  2. python开发_thread_线程_搜索本地文件

    在之前的blog中,曾经写到过关于搜索本地文件的技术文章 如: java开发_快速搜索本地文件_小应用程序 python开发_搜索本地文件信息写入文件 下面说说python中关于线程来搜索本地文件 利 ...

  3. python开发_搜索本地文件信息写入文件

    功能:#在指定的盘符,如D盘,搜索出与用户给定后缀名(如:jpg,png)相关的文件 #然后把搜索出来的信息(相关文件的绝对路径),存放到用户指定的 #文件(如果文件不存在,则建立相应的文件)中 之前 ...

  4. win10无法搜索本地文件,修复方法?

    win10无法搜索本地文件,实在太不方便了,网上查了一圈没几个方法有效的,筛选出来2个成功解决的问题,具体是哪个起到作用,不太清楚,都放上来,大家自行选择! 方法1:按“Windows+ X”后选择“ ...

  5. 遍历并读取指定目录下的所有文件内容,写入Map集合然后输出在控制台和本地文件

    public class FileWrite { public static void main(String[] args) throws Exception { //封装数据源目录 File sr ...

  6. 手工创建tomcat应用,以及实现js读取本地文件内容

    手工创建tomcat应用: 1.在webapps下面新建应用目录文件夹 2.在文件夹下创建或是从其他应用中复制:META-INF,WEB-INF这两个文件夹, 其中META-INF清空里面,WEB-I ...

  7. HTML5如何播放本地文件

    HTML5在操作的过程中,很多朋友会遇到一个问题,那就是在播放本地文件的时候时常会有一些问题存在,使得HTML5才操作的过程中本地文件播放不流畅或者是不能够正常的播放.现在,我们就来看看HTML5如何 ...

  8. FileReader读取本地文件

    FileReader是一种异步读取文件机制,结合input:file可以很方便的读取本地文件. 一.input:type[file] file类型的input会渲染为一个按钮和一段文字.点击按钮可打开 ...

  9. Android Studio上手,基于VideoView的本地文件及流媒体播放器

    既然是第一个Android程序.少不了要Hello World. 1. 新建安卓project watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZm0wNTE ...

随机推荐

  1. JS获取当前时间

    setInterval("getTime();", 1000); function getTime() { //document.getElementById('linkweb') ...

  2. 强大的observejs

    写在前面 各大MVVM框架的双向绑定太难以观察,很难直观地从业务代码里知道发生了什么,我不是双向绑定的反对者,只是认为双向绑定不应该糅合进底层框架,而应该出现在业务代码中,或者是业务和框架之间的代码上 ...

  3. Android中使用AsyncTask实现文件下载以及进度更新提示

    Android提供了一个工具类:AsyncTask,它使创建需要与用户界面交互的长时间运行的任务变得更简单.相对Handler来说AsyncTask更轻量级一些,适用于简单的异步处理,不需要借助线程和 ...

  4. GreenDao3.0新特性解析(配置、注解、加密)

    Greendao3.0release与7月6日发布,其中最主要的三大改变就是:1.换包名 2.实体注解 3.加密支持的优化 本文里面会遇到一些代码示例,就摘了官方文档和demo里的例子了,因为他们的例 ...

  5. 分别用ToolBar和自定义导航栏实现沉浸式状态栏

    一.ToolBar 1.在build.gradle中添加依赖,例如: compile 'com.android.support:appcompat-v7:23.4.0' 2.去掉应用的ActionBa ...

  6. 学习 git基础命令

    缘起 年后到了新公司,由于个人意愿到了一个海外的项目组,除了自己从Java技术栈转了C#技术栈外,很多技术都是第一次使用,学习压力不小啊. 自己也就先从常用的技术开始学起,比如C#,AngularJS ...

  7. hbase开发实例

    1.put/checkAndPut package com.testdata; import java.io.IOException; import org.apache.hadoop.conf.Co ...

  8. Oracle学习笔记五 SQL命令(三):Group by、排序、连接查询、子查询、分页

    GROUP BY和HAVING子句 GROUP BY子句 用于将信息划分为更小的组每一组行返回针对该组的单个结果 --统计每个部门的人数: Select count(*) from emp group ...

  9. Redis在游戏服务器中的应用

    排行榜游戏服务器中涉及到很多排行信息,比如玩家等级排名.金钱排名.战斗力排名等.一般情况下仅需要取排名的前N名就可以了,这时可以利用数据库的排序功能,或者自己维护一个元素数量有限的top集合.但是有时 ...

  10. SQL必知必会1-13 读书笔记

    博主不想写字并向你仍来了一堆代码 1-6 SQL——结构化查询语言,Structured Query Language: 基本按列查询: mysql> SELECT prod_id,prod_n ...