WriteableBitmap inside Windows 10 IBackgroundTask

痴心易碎 提交于 2019-12-24 20:33:14

问题


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:

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

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


回答1:


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

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.



来源:https://stackoverflow.com/questions/35090678/writeablebitmap-inside-windows-10-ibackgroundtask

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!