2

I have got a problem: I would like to use a method Render() for WriteableBitmap object. However, as I noticed, the method is not available without using a Silverlight assembly System.Windows.dll. I need to use RenderTargetBitmap in my project (PresentationCore assembly for standard .net). Here is the problem - there are definitions of some classes in both assemblies, thus they are in conflict.

Basically, I need to add some stuff to Bgra32 bitmap. However, RenderTargetBitmap works only with Pbgra32 ones. I found that using WriteableBitmap to render would be nice. Maybe I am wrong?

Do you have any ideas?

Thank you in advance for the reply!

Cheers

Jamie
  • 1,092
  • 3
  • 22
  • 44

2 Answers2

1

I know this was asked a while ago, but it came up in a search I did for a related issue so I thought I would leave a brief answer for anyone else who stumbled upon it.

Including both the Silverlight and WPF assemblies is NOT a good idea. Pretty much everything you need from Silverlight will be in WPF in one way or another, so unless you are doing a Silverlight project (and not using WPF assemblies) don't include them!

For your problem, converting between Pbgra and Bgra is not particularly difficult and is described here:

http://www.i-programmer.info/programming/wpf-workings/538-rendertargetbitmap-visual-vector-to-bitmap.html.

Besides, RenderTargetBitmap does sort of the same thing as the Render method so you would be better off trying to use that on it's own.

Tim Lloyd
  • 37,954
  • 10
  • 100
  • 130
Guy
  • 3,353
  • 24
  • 28
0

Convert your input to pre-multiplied alpha, do all your calculations in that color space, and convert your output back. Multiplying by alpha isn't hard to code.

Doing all calculations in pre-multiplied alpha color-space often results in better quality output(for example filtering works much better) and has some other advantages too.

Blog-entry on the numerous advantages of using PRGBA

CodesInChaos
  • 106,488
  • 23
  • 218
  • 262