Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wpf performance question: Opacity on Brushes vs Opacity on Elements

I want to know why setting the Brush.Opacity value of element rather than setting the element's Opacity property is better for performance.

From MSDN: Modifying an element's Opacity property can cause WPF to create a temporary surface.

But I can't understand what is temporary surface
Can any one explain? Thanks.

like image 997
Navid Rahmani Avatar asked Jun 29 '11 08:06

Navid Rahmani


1 Answers

If a temporary surface is created, it means a new bitmap is created for the element, the element's contents are rendered to it, and then it is composited onto the parent element's surface using the opacity provided.

Otherwise, if you just set the opacity of the brush, it can bypass this step and just draw directly to the parent element's surface.

Creating a new bitmap and compositing it is more expensive than just drawing directly.

like image 130
Tim Rogers Avatar answered Oct 28 '22 16:10

Tim Rogers