Silverlight 3.0 WriteableBitmap as Texture

Aug 7, 2009 at 10:32 AM
Edited Aug 7, 2009 at 10:33 AM



i have some problems to apply a generated texture to a 3DModell. The new WriteableBitmap class in SVL3 provides
the possibility to generate bitmaps. In the example I generate a simple grid in the red channel (yes: not a very dynamic texture).
Because WriteableBitmap is a BitmapSource I could apply it to a Brush.

But in the scene the texture is not visible. Is there any way to get this working?

Many thanks



Nicky Hochmuth

WriteableBitmap dataImage = new WriteableBitmap(100, 50);

byte[] colors = new byte[4];

colors[0] = (byte)0; // blue
colors[1] = (byte)0; // green
colors[3] = (byte)0; // alpha

for (int i = 0; i < 50; i++)
for (int j = 0; j < 100; j++)
// set the red value
colors[2] = (byte)(i%4==0 || j%4==0 ? 0:255);

// set the pixel color
dataImage.Pixels[i * 100 + j] = BitConverter.ToInt32(colors, 0);

//request a repaint

//set the dynamic createt texture
geometryModel3D.Material = new DiffuseMaterial(new Kit3DBrush(new ImageBrush { ImageSource = dataImage }, 100, 50));



Aug 7, 2009 at 10:37 AM

I'd try converting the writeable bitmap to a standard bitmap first, and make that the imagesource of the brush.

Aug 7, 2009 at 10:47 AM

I have not found any way to convert the WriteableBitmap to a BitmapImage. Do you have something special in mind?

Aug 7, 2009 at 10:50 AM

You can't cast it?

Aug 7, 2009 at 10:55 AM

Are you wanting to bind the writeablebitmap to the brush so that when you change the writeablebitmap it changes the 3d texture?

Aug 7, 2009 at 10:59 AM

Finally this would be nice but i guess this could not work. In general i want to create a dynamic image and bind it to a texture only once.

Aug 7, 2009 at 11:03 AM

I know that you can bind a video brush to a kit3d object - I wonder if that might work for you?

Aug 8, 2009 at 7:33 PM

Hi Nicky,

I've been having the same problem converting adding WritableBitmap to ImageBrush.  I'm trying to covert text to ImageBrush for rendering in Kit3D.

I don't know if you have the same, but did you notice that the imagebrush imagesource returns null even after you have set it to a writablebitmap?

Maybe its possible to use the pixel array that WriteableBitmap exposes to generate an actual Bitmap somehow??


Any ideas gratefully accepted!


Aug 8, 2009 at 9:08 PM

Have a look at these:

Aug 12, 2009 at 8:34 AM

Hello Snelldl

thanks for the links. I could not solve the problem with the WritableBitmap but Joe Stegman's PNG encoder works very well.

So i could create a dynamic texture with transparency for Kit3D and the rendering time is suitable for my problem.

Thx a lot for the help.


Aug 12, 2009 at 3:34 PM

Well, I really didn't do anything, but you're welcome.