RenderTargetBitmap handles the appropriate scaling to provide the correct size. The RenderBitmap object is used and it renders the target in system level pixels not WPF device independent pixels - important because if the bitmap is used anywhere but WPF you'll want standard fixed pixel sizes. This code is supposed to look at the above code and render it into a bitmap. Private void btnSave_Click( object sender, RoutedEventArgs e) With code that essentially does the following: The rectangle then has a Radius X and Radius Y assigned to create the rounder corners. So the idea is to draw the outer container and fill the container with the rectangle. There are some tricky issues to deal with in the shapes - like a Rectangle - aren't controls, but drawings so they don't act like a container. the parent grid) and then render a rectangle into it at the right size and I'm done. So I figured all I'd have to do is stick a Grid inside of the of the fill container (ie. The DockPanel handles the docking of the controls at the top and the save options on the bottom with the grid making up the fill of the rest of the window DockPanel content. The basic set up is this: The middle section of the form above is a Grid that lives inside of a DockPanel. So, I thought how hard could this be? Well it turns out the concept is very simple, but due to some very unexpected behavior in WPF it too a long time and some help from a friend to figure it out. Even nicer, WPF properly respects transparency when rendering to disk, something that's a real bitch in GDI+ when needing to save to GIF images. So the whole point of this exercise was to see how "easy" it'd be to do this because WPF provides the ability to take any rendered visual and lets render it to a bitmap. Trivial, but actually kinda useful - there are a few similar combinations I'm thinking would be useful: Creating gradients (easier and more trivial), creating shadow images etc. It renders in real time as you type so you see immediately what it looks like. The idea is you type in a width, height, radius and color and it will generate the appropriate rounded bar for you. A few hours later I got it working, but there were a few hiccups along the way. Oh ok, so I have tools that do that shit, but I wanted to see what it takes to do this with WPF. Since it's fairly easy to create images and shapes in WPF I thought I'd create a quick form to created rounded corner bars, because one can never have enogh of those in Web applications. One thing I like about WPF is the fact that you can take just about anything that you render on the canvas and dump it out as a bitmap file. I'm playing around a little today with WPF again.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |