paulmoore100

I read lots of posts about this and just want to get the consensus.

I have a winforms / GDI+ app the builds a bitmap from scratch and renders it to the screen and updates it continously (like a video but its not a video). It uses gdi lockbits and a winform picturebox.

It runs OK-ish. I thought I could use wpf becuase

a) wpf draws on the hardware directly so it would go faster (the slow bit of my app is the wm_paint of the invalidates I send every time I change a part of the bitmap, ie the bitblt and render to hardware)

b) I can get pretty effects - zoom, flip3d, ....

Am I wasting my time I am prepared to recode in 100% wpf, in fact i would look forward to it :-)



Re: Windows Presentation Foundation (WPF) making a bitmap from pixels and updating it on the fly

Jeremiah Morrill

I think you might be looking for the BitmapSource.Create() function. Here is a nice example. Also, more fitting, check out Bitmap interop if you want to just use your old gdi code and bring the bitmap into WPF. Check out the methods in System.Windows.Interop.Imaging.

Other than that, there is no low level access to pixel buffers in WPF [yet]. I would really look into a rewrite using WPF and its vector abilities unless you require raster abilities.

If you want a shifty way to get access to the pixel buffer, you can play with this.

Good luck,

-Jer





Re: Windows Presentation Foundation (WPF) making a bitmap from pixels and updating it on the fly

paulmoore100

thx,

first - it has to be bitmap, not vector. The data I have to start with is pixels

I saw your*nasty* code (you should be ashamed of yourself :-) ) for getting at the bitmap insde the BitMapSource - can I write the pixels directly into that (Much like after doing GDI LockBitmap)

THis is a continously updated stream of pixels (like a video), I thought the interop stuff snapshotted a GDI bitmap into a WPF bitmap. It would be prohibitively slow to recopy each time a pixel changed





Re: Windows Presentation Foundation (WPF) making a bitmap from pixels and updating it on the fly

Jeremiah Morrill

Lol, yes, shame on me. Reflection code never looks very elegant.

With the hack you can have access to the pixel buffer and update it on the fly, just make sure you get the bitmap pointer from the class each time you want to change the pixels (the code will unlock the pixels) and run an InvalidateVisual() on your image after u finish the update.

Here is an example where it is being used





Re: Windows Presentation Foundation (WPF) making a bitmap from pixels and updating it on the fly

paulmoore100

thx again.

dumb question - when i try to open the sample project it says vs does not support this type of project. Do I need to download some extra goodies Seems like 1/2 the sample I see croak this way - others work just fine