Reputation: 14426
I was wondering what is the best way to go about taking a selected image, resizing it and saving it. From what i have heard WPF destroys image quality when it resizes images. Is this true, if so what method should i try to attempt this task?
Thanks, Kohan.
Upvotes: 1
Views: 6006
Reputation: 11457
WPF is designed to be able to resize images in real time for display (using graphics card acceleration) and so is biased towards speed over quality.
If you want decent quality you should use System.Drawing.Bitmap
to do your resizing:
System.Drawing.Bitmap resizedImage;
using(System.Drawing.Image originalImage = System.Drawing.Image.FromFile(filePath))
resizedImage = new System.Drawing.Bitmap(originalImage, newSize);
// Save resized picture
resizedImage.Save(resizedFilePath, System.Drawing.Imaging.ImageFormat.Jpeg);
resizedImage.Dispose();
The quality still won't be great - JPEG is a lossy image format and fidelity will be lost by loading and saving and also by the Bitmap
classes crude scaling. If quality must be as high as possible then you should consider using an imaging library such as DevIL, which will do a better job of producing a smoothly resized image.
Upvotes: 3
Reputation: 49649
You don't have to revert back to GDI+ to scale bitmaps. WPF itself has all the APIs you need. The quality is the same: http://social.msdn.microsoft.com/forums/en-US/wpf/thread/580fca03-d15b-48b2-9fb3-2e6fec8a2c68/
Image manipulation is very powerful in WPF plus it is faster than GDI+.
Upvotes: 2