We use images alot in our WPF applications. It is nearly always the case that we have to show the image in different size than it was originally created. To do that, we specify Width and Height for <Image>. WPF caches the image. It is interesting to note that it is not cached as displayed. It is cached as its original size. So if we have a 800 X 600 image which we are just showing as thumbnail size of 50 X 50 by specifying the Height and Width of <Image>, we are caching it as 800 X 600. Now assume we have 100s of these images throughout the application. This would be a big loss for the application memory if we don't specify the Decoded Size explicitly.

In this post, we will be using the same image as used in the previous post. The image is as follows: Let us instantiate this as a BitmapImage in the Resources section of Window.

As you can see that we have specified the DecodePixelWidth and DecodePixelHeight for BitmapImage. This would cache the image as the size specified. Since we are showing the image in the same size in <Image>, it would be shown as follows: This would definitely save a lot in terms of memory usage of the application.
[null, {"document_url": "http://www.shujaat.net/2010/08/wpf-saving-application-memory-by.html", "unformatted_src": "http://3.bp.blogspot.com/_fVxKMZVpfzU/THFe2o0t48I/AAAAAAAAAW0/-54jqth375c/s400/Chundrigar.jpg", "src": "http://3.bp.blogspot.com/_fVxKMZVpfzU/THFe2o0t48I/AAAAAAAAAW0/-54jqth375c/s400/Chundrigar.jpg", "formatted_filename": "Chundrigar"}, null, {"document_url": "http://www.shujaat.net/2010/08/wpf-saving-application-memory-by.html", "unformatted_src": "http://3.bp.blogspot.com/_fVxKMZVpfzU/THFiHLDz6qI/AAAAAAAAAW8/cnS_kIVzXyI/s400/DecodedSize.JPG", "src": "http://3.bp.blogspot.com/_fVxKMZVpfzU/THFiHLDz6qI/AAAAAAAAAW8/cnS_kIVzXyI/s400/DecodedSize.JPG", "formatted_filename": "DecodedSize"}, null, null, {"document_url": "http://www.shujaat.net/2010/08/wpf-saving-application-memory-by.html", "unformatted_src": "http://3.bp.blogspot.com/-StVialkfDd8/UCGhpO3j02I/AAAAAAAABuM/_XHqvYMcULs/s195/MVVMSuvivalGuideCover.png", "src": "http://3.bp.blogspot.com/-StVialkfDd8/UCGhpO3j02I/AAAAAAAABuM/_XHqvYMcULs/s195/MVVMSuvivalGuideCover.png", "formatted_filename": "MVVMSuvivalGuideCover", "rendered_width": 161, "rendered_height": 195}, null, null, null, null, {"document_url": "http://www.shujaat.net/2010/08/wpf-saving-application-memory-by.html", "unformatted_src": "http://1.bp.blogspot.com/-AM-f-uCY_uU/UbDSwj9c0JI/AAAAAAAAF1Q/0iXTkrmoBZU/s195/VSM.png", "src": "http://1.bp.blogspot.com/-AM-f-uCY_uU/UbDSwj9c0JI/AAAAAAAAF1Q/0iXTkrmoBZU/s195/VSM.png", "formatted_filename": "VSM", "rendered_width": 195, "rendered_height": 54}, null, null, null, null, null]