Freigeben über


Bigger isn't always better [How to: Resize images without reloading them with WPF]

**

This blog has moved to a new location and comments have been disabled.

All old posts, new posts, and comments can be found on The blog of dlaa.me.

See you there!

WpfResizeImageSample.zip

Comments

  • Anonymous
    November 11, 2007
    PingBack from http://msdnrss.thecoderblogs.com/2007/11/12/bigger-isnt-always-better-how-to-resize-images-without-reloading-them-with-wpf/

  • Anonymous
    June 20, 2009
    The comment has been removed

  • Anonymous
    June 20, 2009
    Russell, Thanks for the kind words! I'm not sure I understand your scenario, but if you're doing all this work to replace the same image every time (kind of like a flip book?), then maybe it's not worth creating the smaller version of the image anyway since it's just going to be discarded 1 second later anyway. If that's the case, I'd say just let WPF render the big image small and then you can save on this work and extra memory allocation. Alternatively, if you know the dimensions of the source image, you can set both DecodePixelWidth and DecodePixelHeight because you can do the math yourself to maintain the aspect ratio. This is probably the ideal if it's possible. :) Hope this helps!

  • Anonymous
    June 21, 2009
    Thanks for the quick response. Bit of a longer story, but unfortunately I have no choice but to continuously re-do the work (since I need to create a png of each altered thumbnail). I've just started to work through it, but so far what's working much better for me is assigning the FrameworkElement I need to thumbnail to the VisualBrush of a thumbnail-sized Rectangle (instead of using RenderTargetBitmap), then using a RenderTargetBitmap to render the Rectangle. The code actually ends up being quite a bit simpler... I avoid using the 850x425 RenderTargetBitmap AND the CreateResizedImage() code and instead just work with a RenderTargetBitmap of the 90x45 Rectangle. Thanks again for your help!

  • Anonymous
    June 22, 2009
    Russell, Nicely done! I'll be sure to keep that trick in mind. :) Thanks for sharing it!