How to crop image on ScheduledTaskAgent in Windows Phone

血红的双手。 提交于 2019-12-20 04:24:07

问题


I need to crop an image using a ScheduledTaskAgent. Since it runs in the background I get a cross-thread exception when trying to instantiate a WriteableBitmap (as it needs to be created in the UI thread). I have a stream of the image, how would I go about cropping it without using a WriteableBitmap?

Thanks


回答1:


You can use the dispatcher (and therefore the UI thread) even in a background agent:

protected override void OnInvoke(ScheduledTask task)
{
    Deployment.Current.Dispatcher.BeginInvoke(() =>
    {
        // Use the WriteableBitmap here

        this.NotifyComplete();
    });
}


来源:https://stackoverflow.com/questions/13657168/how-to-crop-image-on-scheduledtaskagent-in-windows-phone

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