views:

490

answers:

2
+1  A: 

My first thought was that .NET's jpeg encoder uses chroma subsampling even at the highest quality setting, so color information is stored at half resolution. The setting is hard-coded as far as I can tell. But that wouldn't explain why you would get better quality in the second example. Unless maybe in the 2nd it didn't use antialiasing, giving a sharper (but lower quality) image and the artifacts went unnoticed.

Edit: The dst.Save(m, format); looks like your problem. You're encoding it as jpeg there, with default quality (not 100%), then immediately decoding it back to an image. dst is already an Image (Bitmap class inherits from Image), so you can just return it as-is

David
Thanks for a quick response. I have tried changing the AA settings to see if it helps but it doesn't seem to be the cause of the artefacts. I'm flipping back and fourth between the simple resize and the complex and the artefacts are only present on the complex.
madcapnmckay
Anyone know what the default quality is?
Liam
+1  A: 

I found this example snippet of code (sorry I've forgotten the source) that might help you:

// Create parameters
EncoderParameters params = new EncoderParameters (1);

// Set quality (100)
params.Param[0] = new EncoderParameter(Encoder.Quality, 100);

// Create encoder info
ImageCodecInfo codec = null;
foreach (ImageCodecInfo codectemp in ImageCodecInfo.GetImageDecoders())
{
    if (codectemp.MimeType == "image/jpeg")
    {
        codec = codectemp;
        break;
    }
}

// Check
if (codec == null)
    throw new Exception("Codec not found for image/jpeg");

// Save
image.Save(filename, codec, params);
Alan