1

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(); 
2
  • 1
    As far as I know, jpg is a lossy format. Every save in that format will reduce the image quality. Try doing the same with PNG and see if that too is giving the same issue Commented Dec 5, 2015 at 18:30
  • Or use a JpegBitmapEncoder and set its QualityLevel property to 100. Commented Dec 5, 2015 at 19:28

2 Answers 2

2

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);
}
Sign up to request clarification or add additional context in comments.

Comments

0

WebImage works very well and I use often this class in my application. It has a lot of nice built-in features, for example, saving proportins when resizing an image:

 WebImage wi = new WebImage(imageName);
 wi.Resize(314, 235, true);
 wi.Save(imageName, "png");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.