Mar 21, 2011 at 3:16 AM

I would like to create a rectangle with gradientbrush fill. Is that possible?

Mar 21, 2011 at 8:14 AM

Not possible yet, but it shouldn't be too hard make a linear gradient on base of the existing code.

- Rene Schulte

Mar 21, 2011 at 8:14 AM

Oh, someone actually posted a code snippet you can use right away:

Mar 21, 2011 at 5:13 PM

Thanks for prompt response. mfagerlund's post worked.
Couple of comments/questions:

1. This may be because my non familiarity with  extension methods.
I am using Windows Phone 7 and using the WriteableBitmapExWinPhone assembly.
When I tried to add the extensions by mfagerlund under
public static partial class WriteableBitmapExtensions 
it gave me an error WriteableBitmapExtensions' does not contain a definition for 'Interpolation.
When I changed the partial class to WriteableBitmapExtensions2 it compiled and worked.
Is this the right way to use this?

2. When I used these extensions by rectangle had a small border transparent about a pixel wide. It was noticeable because I am stacking the rectangles on top of each other and doing some rotation animation. How can I remove this border and fill the rectangle completely?




Mar 21, 2011 at 5:25 PM

I fixed the second issue of 1 pixel border by modifying the code and it seems to work!

My modification:

public static void DrawFilledRectangle(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, int color00, int color01, int color10, int color11)

I changed

if (x1 >= w) { x1 = w - 1; }
if (y1 >= h) { y1 = h - 1; }
if (x2 >= w) { x2 = w - 1; }
if (y2 >= h) { y2 = h - 1; }


if (x1 >= w) { x1 = w; }
if (y1 >= h) { y1 = h; }
if (x2 >= w) { x2 = w; }
if (y2 >= h) { y2 = h; }

Mar 21, 2011 at 6:56 PM

Yeah. There's a bug with the current binary. I actually fixed it in my code here, but haven't committed it yet. Good you found and fixed the issue.

- Rene

Mar 22, 2011 at 2:29 AM

Thanks a lot for the great work you guys are doing. I am using your extensions in the geometry related windows phone 7  application I am developing and finding them very easy to use. Keep up the good work.

Mar 22, 2011 at 8:45 AM

No problem. I'm glad you find it useful. 

How's your app called?

Mar 22, 2011 at 2:53 PM

The Windows Phone 7  apps name is 3D Poly Fun.  You can download the free version which has all the features as the paid version with ads. This is a 3D photo application with interesting geometries.  18 different polyhedra can be used to animate pictures and colors. The polyhedron can be animated by opening or closing them as well as rotating them. The polyhedra can show custom colors, pictures from media library.  I used the Writeablebitmapex to create user selection color rectangles on the fly. The Writeablebitmapex enabled me to save the user selected color rectangles in the isolated storage. In this app instead of using the whole library I used snippets from the source code.

I am also developing another application ( which I have not named yet) where I will be using many more features of   the Writeablebitmapex windows phone 7 binary. In this app I will be using the clone, gradient (which we discussed in the post), transforms and other features.  I will post a note here when it is ready.

I think the major strength of the Writeablebitmapex is how fast I could use it without knowing too much about the internal workings.

I have a suggestion to make. It was little bit difficult for me to dig through to find the Windows Phone 7 binary. A more easy way to do this with some documentation might be useful.

Again I have to complement you and your team for excellent work which has simplified  and enhanced my coding  life.