开发者

InteropBitmap synchronization

开发者 https://www.devze.com 2023-03-09 04:26 出处:网络
WPF InteropBitmap can be created from shared memory, i开发者_运维知识库.e. Imaging.CreateBitmapSourceFromMemorySection()

WPF InteropBitmap can be created from shared memory, i开发者_运维知识库.e.

Imaging.CreateBitmapSourceFromMemorySection()

In this case, we can update shared memory in another thread or process, and then after updating, calling InteropBitmap.Invalidate() to present the changes.

From the WPF source code, InteropBitmap is just a wrapper of IWICBitmap, but it doesn't expose IWICBitmap::lock which is used for exclusive writing.

So, how do I sync writing and reading of WPF InteropBitmap?

  1. Updating occurs in user's thread.
  2. Reading always occurs in WPF internal render thread via IWICBitmapSource::CopyPixels

Thanks


You can create a WrapperClass which exposed a lock object and the methods to manipulate the Image. Is some work but would work 100%

something like:

class InteropBitmapSyncWrapper
{

    public InteropBitmapSyncWrapper(InteropBitmap wrappedBitmap)
    {
        WrappedBitmap = wrappedBitmap;
        this.Lock = new Object();
    }

    public InteropBitmap WrappedBitmap
    {
        get;
        set;
    }

    public Object Lock
    {
        get;
        private set;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消