Windows 10 IBackgroundTask 中的 WriteableBitmap [英] WriteableBitmap inside Windows 10 IBackgroundTask

查看:23
本文介绍了Windows 10 IBackgroundTask 中的 WriteableBitmap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 Windows 10 应用程序 (UWP) IBackgroundTask 的 Run 方法中裁剪图像.为了实现我正在使用 WriteableBitmapEx 但在我尝试实例化一个新对象的那一刻,我得到了异常:

I am trying to crop an image from a Run method from Windows 10 app (UWP) IBackgroundTask. To achive that I'm using the WriteableBitmapEx but at the moment that I try to instantiate a new object, I got the exception:

应用程序调用了一个接口,该接口被编组用于不同的线程.(来自 HRESULT 的异常:0x8001010E(RPC_E_WRONG_THREAD))

The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))

我尝试使用一些 Dispatcher,但发生了其他异常.有什么想法吗?

I have tried to use some Dispatchers but other exception ocurred. Any idea?

推荐答案

WriteableBitmap是一个UI对象,需要UI线程,后台任务没有.

WriteableBitmap is a UI object, and requires UI thread, which background task lacks of.

根据您的需要,您可以使用不同的 API 来处理图像(检查 本主题 BitmapEncoder) 或从 XamlRenderingBackgroundTask,它将在 UI 线程中调用其 OnRun 方法.尽管请记住,由于内存限制,建议在 XamlRenderingBackgroundTask 中使用 C++.

Depending on your needs, you can either use different API to work with images (check this topic for BitmapEncoder) or derive your background task from XamlRenderingBackgroundTask, which will call its OnRun method in UI thread. Although keep in mind, that it's recommended to use C++ in XamlRenderingBackgroundTask due to memory limitations.

这篇关于Windows 10 IBackgroundTask 中的 WriteableBitmap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆