You can get the source code for my WPF Photo Print utility here and on CodePlex. Some interesting bits are:
- All transformations are applied to Drawing objects. Take a look in the ‘Transformations’ folder and you’ll notice creating new ones is just a case of overriding GetDrawing.
- The crop selection uses an Adorner (based on an MSDN sample) combined with an OpacityMask (see Preview.xaml) and plenty of data binding.
- Although it’s designed for photo printing, the transformations could be applied to any base drawing. Just derive something from Transformable; it should (could) even work for video
- Currently it only prints the results, but it’d be a piece of cake to draw to a RenderTargetBitmap and save to a file (in any DPI you choose).
Hope you find it useful (I’ve already printed plenty of photos with it — it’s great!
)


16 comments
Comments feed for this article
August 22, 2008 at 1:24 am
WPF Photo Print (.NET 3.5 SP1) « Chris Cavanagh’s Blog
[...] July 29, 2008 · 5 Comments UPDATE: Source code now available here. [...]
August 22, 2008 at 7:30 am
Dew Drop - August 22, 2008 | Alvin Ashcraft's Morning Dew
[...] WPF Photo Print – Source Code (Chris Cavanagh) [...]
September 2, 2008 at 11:40 am
Silverlight Cream for August 23, 2008 -- #354
[...] Dynamically loading ListView Templates again, and DZ and Mandelbrot. From SilverlightCream.com: WPF Photo Print – Source code Not Silverlight, but it’s WPF code… so that’s close
… Chris Cavanagh posted the code to his [...]
October 8, 2008 at 4:57 am
Luca
Hi Chris ! Have any idea how to save image in original image resolution ??
October 8, 2008 at 9:36 am
Chris Cavanagh
Luca – Basically you just need to create (and draw to) a RenderTargetBitmap of the appropriate size. I’ll get a sample / update uploaded as soon as I can (I’ve been meaning to do some tweaks but have been busy / procrastinating
).
September 3, 2010 at 2:12 pm
Faye
Hi Chris Great application! I saw your post about a sample/update to show how to render to a Target bitmap and save it. Can you tell me where I could find this code if you got a chance to create a sample?
September 3, 2010 at 2:36 pm
Chris Cavanagh
Faye – Looks like I didn’t get around to doing this yet; however your comment might be just the motivation I need
It should be pretty straightforward… Do you want it to pop open a save dialog, or are you using the code in your own app and just need an example?
September 3, 2010 at 2:53 pm
Faye
Hi Chris! It wouldnt let me reply back to your follow up. I would like to just save to a directory that I specify. Thank you!!!!! It is greatly appreciated!
September 3, 2010 at 9:34 pm
Chris Cavanagh
Faye – I’ve updated the ClickOnce app and the source on CodePlex. It now requires .NET 4 (instead of 3.5). The save functionailty is very basic and a bit quirky:
- If you use File -> Save as, it’ll only save the image that is both selected and checked. Because it can be used to save a batch of files at once, the final filename will be (new)_(original).extension (so if your original is called Original.jpg and you tell it to save as New.jpg, the final filename(s) will be New_Original.jpg). Totally confusing huh?
Sorry about that; it was just the quickest way to throw it in there…
- If you use Save and Export -> Save, it’ll save all checked images (regardless of which is currently selected). The same weird file naming rules apply.
- It’ll always scale the images to fit a 3000×3000 box. This is arbitrary (but not yet configurable)… Mainly because the app normalizes all image sizes internally; it could probably figure out a more appropriate size, but I’ll save that for later if/when I’ve more time
Hope this helps!
September 7, 2010 at 7:42 am
Faye
Hi Chris! Thank you very much for updating this so quickly! I greatly appreciate it! I hope you had a great weekend. I am going to take a look at it now. Again thank you.
Faye
January 25, 2009 at 12:44 pm
toddpi314
tight, I will check out the source.
Just wondering, was this project ported or did you start from scratch?
January 25, 2009 at 9:31 pm
Chris Cavanagh
toddpi314 – It wasn’t a port — I just needed a simple photo crop/rotate utility that didn’t need files importing into a library. WPF made writing this pretty easy
August 23, 2010 at 12:42 pm
Whitey
Hey Chris,
I like your code, and it touches on part of the issues that I’m tackling now. However, I need to be able to crop part of a photo (working on using polygons), and paste the cropped area back onto the original photo.
I will be blurring the lines between the cropped region and the original in the end. However, I wondered if you’d been able to, in WPF, combine two images?
Thanks,
Whitey
August 24, 2010 at 10:49 pm
Chris Cavanagh
Whitey – Are you just combining images for display, or is this to output to a png/jpg? Combining shouldn’t be tricky; the easiest way is probably add both images to a Grid, then render the whole grid to a RenderTargetBitmap… Or I could have misunderstood your question, so let me know if I’m barking up the wrong tree
September 1, 2010 at 12:08 pm
Whitey
Hey Chris,
Sorry it’s been a while, but I got swamped. The intent of my project is to allow the user to mark a region, and I make that region a floater. They can then move and rotate it, and finally re-affix it to the source image. They can then use a brush to blur or paint the edges so the it looks more natural. They could then save it for a side by side comparison.
I’ve actually had some luck making the floater, and applying the Render Transforms. However, I’m have some issues with the use of rotation skewing my rectangle region I want to add back. Once the y value on the top right is different from the y value on the top left the cropped area becomes a region inside of a larger rectangle.
Thanks for your time
Whitey
September 3, 2010 at 10:52 am
Chris Cavanagh
Whitey – Can you send me some sample code demonstrating the problem? (presumably could reproduce issue with just XAML?).