InteropBitmap synchronization
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?
- Updating occurs in user's thread.
- 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;
}
}
精彩评论