Reputation: 21
I have been trying to load my image in bitmap image class. But whenever I am trying to save an image (using a third party library called Image Processor) the quality drops. So my question is that:
Is there any way i can save image in its full quality?
src.BeginInit();
src.UriSource = new Uri("picture.jpg", UriKind.Relative);
src.CacheOption = BitmapCacheOption.OnLoad;
src.EndInit();
Upvotes: 1
Views: 3043
Reputation: 12642
You can achieve image saving without any thirdparty libraries. But you should know, that saving JPEG always drops quality a bit - its a nature of that format, not an issue with library. Using the JpegBitmapEncoder
you can configure the quality, and with the maximum value you will not see a picture degradation, but anyway it present. So, consider using of PNG format instead.
Here is a short snippet how to load and save a JPEG image:
// Load from file or any other source.
var uri = new Uri(@"D:\InputImage.jpg");
var bitmap = new BitmapImage(uri);
// Save to file.
var encoder = new JpegBitmapEncoder(); // Or any other, e.g. PngBitmapEncoder for PNG.
encoder.Frames.Add(BitmapFrame.Create(bitmap));
encoder.QualityLevel = 100; // Set quality level 1-100.
using (var stream = new FileStream(@"D:\OutputImage.jpg", FileMode.Create))
{
encoder.Save(stream);
}
Upvotes: 2