- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在我的应用程序中,我需要从使用文件选取器选取的文件中抓取缩略图。当文件选取器返回一个没有缩略图的文件(例如空的 *.bmp 文件)时,以下行将引发 COM 异常。我该如何避免这种情况?
StorageItemThumbnail t = await f.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.DocumentsView);
编辑:其他详细信息,我的意思是 .bmp 而不是 .png 抱歉...
重现:
异常详情:
System.Runtime.InteropServices.COMException was unhandled by user code
HResult=-2147467259
Message=Error HRESULT E_FAIL has been returned from a call to a COM component.
Source=mscorlib
ErrorCode=-2147467259 StackTrace: at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() ---some stuff ommitted---
InnerException: null
启动文件选择器的代码:
public static async Task<IReadOnlyList<StorageFile>> PickMulipleFilesAsync()
{
FileOpenPicker picker = new FileOpenPicker();
picker.SuggestedStartLocation = PickerLocationId.Desktop;
picker.FileTypeFilter.Add("*");
var files = await picker.PickMultipleFilesAsync();
return files;
}
最佳答案
正如上面的评论以及 MSDN 论坛上的某人所提到的。解决方法是在 try-catch block 中调用 GetThumbnailAsync 并在没有缩略图时放置占位符图像。
StorageItemThumbnail t=null;
BitmapImage thumbnailImage= new BitmapImage();//image used for display
try{
t = await f.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.DocumentsView);
}
catch(Exception e){
t = null;
}
if (null == t)
thumbnailImage = placeholder;//no thumbnail then use the placeholder image
else
thumbnailImage.SetSource(t);
关于c# - 没有缩略图的文件在 Win 8 Metro 中抛出 COM 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9525466/
我有一个具有可变数量子元素的固定大小的 div。我不知道 children 的大小。目标是缩小它们以适合父级。 例子: .parent { width: 100px; height: 100p
我是一名优秀的程序员,十分优秀!