BitmapEffect Begone

You can do really neat things with Bitmap Effects in WPF. Shadow, Bevel, Outer Glow can all have a great impact on how your application looks. But you should be aware that they don't come cheap. They are rendered in software, which yields very poor performance. Also, ClearType is turned off on elements that have them applied, so your text becomes blurry.

So, what to do?

  • Abstinence. Now, I'm not really a prude, but in this case, minimizing the use of bitmap effects can significantly improve performance.
  • Apply only on simple Visuals. Probably the most important advice here. If you want to apply an effect on a complex Visual, use layers! Apply the BitmapEffect on a simple Shape (e.g. Rectangle, Path), and use a Grid, for example, to position it below your complex Visual. Do not apply the effect on a Decorator (such as a Border) that contains your Visual, since that will cause the entire visual tree to suffer from the effect.
  • Avoid Animations. Especially on large Visuals, avoid animating the BitmapEffect's properties, and animating elements that have effects applied on them. TextBoxes, for example, animate the cursor frequently when they are focused, so if an element that has an effect contains a TextBox, it is forced to render itself entirely every blink.
  • Use Bitmaps. Yes, it's true bitmaps don't scale like vectors, but in some places they are a very viable alternative.

  • How nine-grid images work
    Use Nine-Grid Images. Have you ever wondered how the themes on XP and Vista work? You can stretch a button as much as you like and it still looks good. They use nine grid images. The idea is very simple: divide the image to nine areas and stretch it as shown in the illustration. The effect is that the proportions of the corners and borders are always maintained. I've attached a project with a NineGridBorder class that can be used to draw these images. After I wrote it, I discovered another implementation, so I took the best of both of them. 
  • Vectorize. When exporting from Expression Design to XAML, you have the option to either rasterize (i.e. create a bitmap) or vectorize some of the effects. For example, when applying soft edges to a vector drawing, ED exporter will create a Canvas that contains a few layers with different opacities, which will simulate the effect.
  • Use WpfPerf. This is a great tool that comes with the Windows SDK. You can use Perforator to detect whether your careless colleagues used BitmapEffects or other ill-advised features that may hinder your application's performance. Check "Draw software rendering with purple tint" to immediately view what causes problems. Try to resize the window or run animations while this is checked.
Published 02-09-2007 1:30 PM by aelij
Filed under:

Comments

# re: BitmapEffect Begone

Wednesday, January 30, 2008 9:32 AM by Rob Ainscough

So basically why use WPF if you can't use many of the "cool" features is provides?

And this begs the question, why did Microsoft even release it like this?  Another experiment that has no future?

# re: BitmapEffect Begone

Wednesday, January 30, 2008 9:45 AM by aelij

Hardly. Bitmap Effects are a very small part of WPF, and you can get along just fine without them. They may become hardware accelerated in V2, which will make them more usable.

WPF is a very innovative UI platform. It enables you to deal with immensely complex scenarios with great ease. It feel more "right", since it was designed almost "tabula rasa" with regards to Win32. Give it try, you'll quickly see what I mean.

# re: BitmapEffect Begone

Wednesday, January 30, 2008 2:33 PM by Rob Ainscough

I have been trying it for some time now.  It has some pretty significant "gotchas" that really should have been resolved BEFORE releasing:

1.  Data Binding is worky

2.  Single-threaded apartment

3.  No MDI

4.  No support for compressed images/icons

5.  No native hooks into Vista

WPF can do what can already be done with a host of 3rd party controls.  If you look at considerably lesser funded tools on other platforms like OS X, WPF has much work to do to catch up with Apple Quartz API.

Is there going to be a version 2 of WPF?  Or is this just another technology to be faded out for something completely different with once again NO migration path?

Currently WPF's performance in both development mode under VS 2008 IDE and in deployed mode, leave MUCH to be desired -- actually not really acceptable from a client perspective.

# re: BitmapEffect Begone

Thursday, January 31, 2008 2:20 AM by aelij

I agree some things are missing, but in my opinion the advantages far outweigh the disadvantages. More specifically:

- Data binding works great, in my opinion. It allows you to truly separate data from UI.

- STA is bad, I agree.

- MDI is becoming a thing of the past. It is far less convenient than other options (such as tabs). However, there are 3rd party controls that implemented MDI for WPF.

-

You can't compare Quartz, which is a low(er) level API, to WPF. WPF is a UI library, not a graphics library. (Quartz is comparable to MILCORE, which WPF uses internally, though.) I'm not familiar with any 3rd party tools (on Windows) that can really do what WPF can, in the same amount of development time. Yes, performance can be better, and I believe it will be.

As for the future, there have already been some improvements to WPF in .NET 3.5, and the next release will continue to improve. WPF is the first non-Win32-based UI platform MS has released, and they're investing heavily in it.  So don't give up on it too soon :-)

# re: BitmapEffect Begone

Friday, August 22, 2008 9:25 AM by Josh Usovsky

Regarding Mr. Cranky's post:

1.  "Data Binding is worky"

 I don't see anything wonky about it.  It's easy to use, easy to implement in custom objects, and makes a lot of sense.

2.  "Single-threaded apartment"

 Big deal.  Most of the UI "work" is already done on the GPU anyway, so we won't see much of a performance boost in rendering.  Free-threading would result in the headaches sometimes encountered in Winforms, and in most situations, there's no compelling reason for it.  You're still able to thread to your heart's content in your own app.

3.  "No MDI"

  Maybe it's time to leave 1995 behind.  Just let it go, man.

4.  "No support for compressed images/icons"

  I think what you mean is compressed PNG.  Yes, that's a shame, but in most cases it's not a hardship to use uncompressed ones.

5.  "No native hooks into Vista"

  The API is available for Windows XP, too.  It's certainly less convenient, but you can hook all you want with pinvoke.

# Shady Pixels

Sunday, October 19, 2008 1:06 PM by TrackBack

In my previous post I mentioned the new Zune 3.0 visualizations. I really liked them, so I decided to

# re: BitmapEffect Begone

Friday, July 23, 2010 5:53 AM by MyrnaRichardson34

People deserve very good life time and <a href="bestfinance-blog.com/.../personal-loans">personal loans</a> or just term loan will make it much better. Because freedom is based on money state.

# re: BitmapEffect Begone

Tuesday, July 27, 2010 8:14 PM by courseworks

Custom course works writing companies are proud of providing premium quality. Furthermore, high school students select to order coursework online. Such guys always have got great grades.

# re: BitmapEffect Begone

Thursday, July 29, 2010 4:50 AM by online essays

Adept research paper usually  includes fantabulous intentions, distinctlywritten thoughts, and supportive demonstrate. You can be assuredyou are getting honorable quality of work available from first-class essay writing.

# re: BitmapEffect Begone

Sunday, August 08, 2010 3:21 AM by order essay

Thanks a lot that you created the superb writing connected with this good post. Though, to select the really good writing service, all students have to have some information just about custom writing.

# re: BitmapEffect Begone

Tuesday, August 10, 2010 2:20 PM by coursework

That's no need to bother just about your academuic grades, just because you can usually buy course work writing service and relieve your coursework creating stress.  

# re: BitmapEffect Begone

Thursday, August 19, 2010 2:54 AM by custom essay writing

We can speak for a long time about the historical knowledge of term paper writing, but will recognize that the essay order service can write the famous quality custom written essays at all time. Is that correct?

# re: BitmapEffect Begone

Sunday, August 22, 2010 2:31 PM by admission services

At present, a lot of students are assured that the custom papers writing service can be the great point to purchase research essay from. Moreover, this is really great way to improve a writing technique!

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Please add 7 and 7 and type the answer here:
Powered by Community Server (Non-Commercial Edition), by Telligent Systems