views:

166

answers:

1

Ill try to explain my situation as best as I can, sorry if it is not too clear...

I have a Viewport3D that contains some large 3d rectangles that are like big crystals.

When the user click on one of the crystals, I add a new material to the crystal in the spot the use clicked using an ImageBrush. I then iterate over a list of bitmaps (List<BitmapImage> collection) and update the ImageBrush each frame to create an animation on the 3D crystal.

This works nice and I have up to 5 different effects playing on the crystals, but after profiling my application, I have discovered that due to mipmaps (I think) and the way 3d renders, my video memory jumps through the roof!!

By my calculation, if I have a 75 frame animation, by 400x400 running at 4 bytes per pixel, and having ~5 different animations piled up, you can see how this can get large :)

75 * 400 * 400 * 4 * 5 = ~250MB

this is an issue, not only because of the size, but also, the BitmapImages stay in Video Memory until I make them null, which is very annoying and performance costly.

My idea to fix this is to change from having List<BitmapImage> collection, to having a List<Byte[]> and rather than updating an ImageSource, I would like to try to use a WriteableBitmap that write the bytes to it.

The issue is I have no idea how to read bytes from a PNG file, then create a WriteableBitmap and write the bytes to it over and over in an efficient manor.

Can anyone please help me out?

+1  A: 

WriteableBitmap is actually pretty bad with performance, even though it takes dirty regions. Try using the InteropBitmap. I have an class ready to go for it here:

http://silverlightviewport.codeplex.com/SourceControl/changeset/view/33100#809062

Jeremiah Morrill
Hey thanks! The big questions here are, 1 will that perform at a reasonable rate, and will using a technique like this help with video memory reduction?
Mark
Also I have having trouble getting an image displayed in WPF using that class, using a byte[]... can you please provide a sample?
Mark
Try Marshal.Alloc and Marshal.Copy to allocate native memory and copy your managed byte array to your native buffer
Jeremiah Morrill