WriteableBitmap in WPF
-
Wednesday, September 29, 2010 2:48 PM
I am trying to port an application from Silverlight to WPF and would like to get some help. I am quite experienced in the former, but not so in the latter. It turns out to be surprisingly difficult.
I managed to get the WPF code to dual compile in Silverlight and WPF (with tons of features turned off in the WPF version, for now), but I am very much stuck with getting the equivalent of WriteableBitmap to work.
Yes WPF supports WriteableBitmap but apparently in a very different fashion. I did some research (including going to the WPF forum) and the answers are either old or less than satisfactory. For example, someone wants to update some line drawings 10 times a second, and the answer was "the initial implementation of WriteableBitmap did not provide adequate performance for scenarios like yours". Really?
So does anyone have a solution to this problem? Ideally it would satisfy the following:
(1) Use WriteableBitmap or something equivalent that allows easy read/write access to the pixels, without having to copy in/out the whole thing for each access.
(2) Allow the use of WriteableBitmap.Render() and Invalidate() or something equivalent.
As an example, I would like to get the following code working in <1 seconds (certainly doable in Silverlight). The code is meaningless other than to demonstrate what I would like to be able to achieve in reasonable amount of time.
Image image = makeImage(); // some 100x100 image; WriteableBitmap wb = new WriteableBitmap(1024, 768); for (int i = 0; i < 256; i++) wb.Render(image, getTransform(i)); // draw the same image 256 times, with offsets; wb.Invalidate(); int count = 0; for (int i = 0; i < 1024 * 768; i++) if (((wb.Pixels[ i ] >> 24) & 0xff) > 0) count++;
Your help would be appreciated. Thanks!
All Replies
-
Wednesday, September 29, 2010 4:42 PM
ok read this carefully :
The Idea is using Parallel Extensions and enhancing the multi threading issues
http://khason.net/blog/how-to-high-performance-graphics-in-wpf/
-
Wednesday, September 29, 2010 7:28 PM
Thank you for your answer and I indeed read the article carefully. It does not solve my problem though. I understand the principle behind the technique, but I want something somewhat compatible with the Silverlight version of WriteableBitmap. Faster bitmap manipulation is something that I've figured out already, but I haven't figured out how to do that and Render() and Invalidate() at the same time.
-
Tuesday, October 05, 2010 1:23 PM

