wpf net 3.0 Changing Colors in a bitmap

R

Rolf Welskes

Hello,
because there are no news group for window presentation foundation and one
has told me I can use this, here my problem:

I have a bitmap in wpf for example using BitmapImage.

Now I want to change brightness, Colors etc.

In gdi+ this was done by using a color-matrix, in windows presentation
foundation do not find any way to do this.
For example to change a green to a brighter geen, in gdi+ I had colormatrix
to change color angles.

Thank you for any help.
Best Regards
Rolf Welskes
 
W

Walter Wang [MSFT]

Hi Rolf,

In WPF, you can use BitmapEffect to apply visual effects. We have 5
built-in effects: Blur, DropShadow, OuterGlow, Bevel, Emboss. However, we
currently don't have a built-in effect to change brightness or contrast,
but you can create a custom BitmapEffect to do this:

#WPF Bitmap Effects
http://msdn2.microsoft.com/en-us/library/ms735322.aspx#related_topics


Hope this helps.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

Rolf Welskes

Hello,
thank you for your informations,
but this is very problematic.
Because all is in software no accelaration by the graphic card.
Think on a 3D-Scene, I have a gray think, whatever.
Now I take a light which changes from red to blue,
This I this is possible as animation, so the think looks first red and then
slowly goes over to blue.

But this I cannot do with a simple 2D bitmap - is this reality?

Thank you and best regards
Rolf Welskes
 
R

Rolf Welskes

Hello,
I have tried the Bitmap Effect sample.
But I get an AccessViolationException: try to access secured memory or
similar.

Does the example not work?

Thank You
Rolf Welskes
 
W

Walter Wang [MSFT]

Hi Rolf,

I tested the sample and did find the issue you mentioned. The code should
be corrected to:

public class RGBFilterBitmapEffect : BitmapEffect
{

unsafe protected override SafeHandle CreateUnmanagedEffect()
{
const uint CLSCTX_INPROC_SERVER = 1;
Guid IID_IUnknown = new
Guid("00000000-0000-0000-C000-000000000046");
Guid guidEffectCLSID = new
Guid("84CF07CC-34C4-460f-B435-3184F5F2FF2A");
SafeHandle wrapper = BitmapEffect.CreateBitmapEffectOuter();

COMSafeHandle unmanagedEffect;
uint hresult = Ole32Methods.CoCreateInstance(
ref guidEffectCLSID,
wrapper.DangerousGetHandle(),
CLSCTX_INPROC_SERVER,
ref IID_IUnknown,
out unmanagedEffect);
if (hresult != 0)
throw new Exception("Cannot instantiate effect. HRESULT = "
+ hresult.ToString());
InitializeBitmapEffect(wrapper, unmanagedEffect);
return wrapper;

}


Also, you need to manually register
RGBFilterEffect\RGBFilterEffectLib\Debug\RGBFilterEffectLib.dll using
regsvr32.exe.



----------


For your another question about the performance, currently WPF version 1.0
BitmapEffect is only using software mode. Therefore the performance issue
does exist. Please feel free to submit your feedback here:
http://connect.microsoft.com/Main/content/content.aspx?ContentID=2220.



Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

Rolf Welskes

Hello,
thank you for you help - was a realy help for me.
Thank you and best regards
Rolf Welskes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top