获取文件的缩略图Thumbnail和通过 AQS - Advanced Query Syntax 搜索本地文件
演示如何获取文件的缩略图


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 搜索本地文件的更多相关文章
- 重新想象 Windows 8 Store Apps (22) - 文件系统: 访问文件夹和文件, 通过 AQS 搜索本地文件
原文:重新想象 Windows 8 Store Apps (22) - 文件系统: 访问文件夹和文件, 通过 AQS 搜索本地文件 [源码下载] 重新想象 Windows 8 Store Apps ( ...
- python开发_thread_线程_搜索本地文件
在之前的blog中,曾经写到过关于搜索本地文件的技术文章 如: java开发_快速搜索本地文件_小应用程序 python开发_搜索本地文件信息写入文件 下面说说python中关于线程来搜索本地文件 利 ...
- python开发_搜索本地文件信息写入文件
功能:#在指定的盘符,如D盘,搜索出与用户给定后缀名(如:jpg,png)相关的文件 #然后把搜索出来的信息(相关文件的绝对路径),存放到用户指定的 #文件(如果文件不存在,则建立相应的文件)中 之前 ...
- win10无法搜索本地文件,修复方法?
win10无法搜索本地文件,实在太不方便了,网上查了一圈没几个方法有效的,筛选出来2个成功解决的问题,具体是哪个起到作用,不太清楚,都放上来,大家自行选择! 方法1:按“Windows+ X”后选择“ ...
- 遍历并读取指定目录下的所有文件内容,写入Map集合然后输出在控制台和本地文件
public class FileWrite { public static void main(String[] args) throws Exception { //封装数据源目录 File sr ...
- 手工创建tomcat应用,以及实现js读取本地文件内容
手工创建tomcat应用: 1.在webapps下面新建应用目录文件夹 2.在文件夹下创建或是从其他应用中复制:META-INF,WEB-INF这两个文件夹, 其中META-INF清空里面,WEB-I ...
- HTML5如何播放本地文件
HTML5在操作的过程中,很多朋友会遇到一个问题,那就是在播放本地文件的时候时常会有一些问题存在,使得HTML5才操作的过程中本地文件播放不流畅或者是不能够正常的播放.现在,我们就来看看HTML5如何 ...
- FileReader读取本地文件
FileReader是一种异步读取文件机制,结合input:file可以很方便的读取本地文件. 一.input:type[file] file类型的input会渲染为一个按钮和一段文字.点击按钮可打开 ...
- Android Studio上手,基于VideoView的本地文件及流媒体播放器
既然是第一个Android程序.少不了要Hello World. 1. 新建安卓project watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZm0wNTE ...
随机推荐
- css设置table表格tr分离
table { border-collapse:separate; border-spacing:10px 50px; }
- git push不用重复输入用户名和密码(解决方案)
每次git push都要输入用户名和密码,有点麻烦,就上网搜了下解决方案. 网上的解决方案有的讲得不清晰,逐个试了后,总结下两种有效的解决方案. 方案一: 1.在计算机安装盘(即一般为C盘)下找到 ...
- java web学习总结(三十一) -------------------EL表达式
一.EL表达式简介 EL 全名为Expression Language.EL主要作用: 1.获取数据 EL表达式主要用于替换JSP页面中的脚本表达式,以从各种类型的web域 中检索java对象.获取数 ...
- DOM对象与jQuery对象的相互转换
DOM 对象可以使用 js 中的方法, 不能使用jQuery中的方法:jQuery对象只能使用jQuery中的方法, 不能使用js中的方法:jQuery对象是通过jQuery包装DOM ...
- ArcGIS Engine开发前基础知识(4)
ArcGIS不同开发方式的比较 关于GIS应用软件的开发,通常有三种方式:C/S架构.网络GIS和移动GIS.ArcGIS平台提供了对三种开发方式的支持,对于采用从C/S架构的大多数开发者来讲,首先想 ...
- Android requires compiler compliance level 5.0 or 6.0. Found '1.4' instead的解决办法
今天在导入工程进Eclipse的时候竟然出错了,控制台输出的是: [2013-02-04 22:17:13 - takepicture] Android requires compiler compl ...
- maven 打包含有第三方依赖的 jar 包
maven 打包含有第三方依赖的 jar 包:mvn assembly:assembly
- mac,/usr/local is not writable 解决方法
mac,/usr/local is not writable 解决方法 mac 问题 今天在mac上装mongodb,发现提示权限不足问题,错误提示如下: mac安装mongodb错误提示.jpg 尝 ...
- SQL:执行顺序
SELECT语句的执行的逻辑查询处理步骤: (8)SELECT (9)DISTINCT(11)<TOP_specification> <select_list>(1)FROM ...
- (总结)Oracle 11g常用管理命令(用户、表空间、权限)
1.启动oracle数据库: 从root切换到oracle用户进入:su - oracle 进入sqlplus环境,nolog参数表示不登录:sqlplus /nolog 以管理员模式登录:sqlpl ...