C
C#10mo ago
Will

✅ Drawing WPF image from byte array

Is there any way in wpf to render an image directly from a byte array? eg accessing DirectX? i want something like glTexSubImage2D where an array can be provided and it will simply be copied to the gpu for rendering. i can't use a WriteableBitmap because the memory safety is too performance limiting for my use. (i'll be writing and reading large areas to it 60 times a second)
4 Replies
SWR
SWR10mo ago
Yes and no. You're asking two separate questions. You can render directly to a wpf control by drawing to it's bitmap handle in a paint event. To be clear, that's how it works in win forms at least. Wpf is slightly different but it's the same idea. But if you want to access the GPU, then wpf will not give you any practical ways to do that. You're better off using GL, DirectX, or vulkan.
Will
Will10mo ago
got it, thanks. sorry for the confusion, my question should have been more along the lines of "can i access the directx context that wpf has already" i assume the direct rendering you are talking about is OnRender(DrawingContext dc)? seems like it needs an ImageSource which would be too slow for the constant updates i would need to provide it
SWR
SWR10mo ago
You probably can, but if you're doing that, you're better off just rendering to a DX surface. What are you trying to draw?
Will
Will10mo ago
just a 2d 32bit rgba texture directly or at least close to direct as possible, from a byte array, since performance is critical and i don't want to make new allocations, thread checking, streams etc that ImageSource's and their inheritors do i've looked around a bit more and wpf just doesn't seem to have anything that low level which is fair enough, i'll just use a 3rd party library i think 🙂