vendredi 27 février 2015

Generate banded image quickly?

I need to generate preview images of walls for display dynamically. All of them will consist of bands of varied color and width and should look something like this:


sample wall


Right now I have it working but it's kind of slow (not terrible, but enough that it feels a little lag-y) and I'm wondering if there is a better way.


What I am currently doing is constructing wpf objects in code. I construct a grid as the main container, then a stack panel that is the preview, then a textblock that has a label at the bottom (cropped out of this image, sorry), then I add border objects for each of the layers (bands) with a border thickness for the outline and the proper color as the background, etc. Then i use



RenderTargetBitmap bmp = new RenderTargetBitmap((int)gd.ActualWidth, (int)gd.ActualHeight, 96, 96, PixelFormats.Pbgra32);
bmp.Render(gd);


Where gd is the grid object that holds the stack panel and text block and then use this as the image source.


The reason I'm using image source instead of directly using the WPF objects is two fold. First, I have other objects that are actual image files that need to load and preview, so they come is as image source, not a WPF visual. Second I have a thumbnail and a full preview. I would like to be able to show the thumbnail as a scaled down version of the preview and if it's wpf objects I don't think you can do that (at least not easily).


Anyway if anyone has an better way to do this I would definitely appreciate it...


Aucun commentaire:

Enregistrer un commentaire