How to crop image on ScheduledTaskAgent in Windows

2019-03-01 01:19发布

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条回答
forever°为你锁心
2楼-- · 2019-03-01 01:51

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();
    });
}
查看更多
登录 后发表回答