My source images are 2288px x 1712px and 816kb. When I create a thumbnail of 1024 x 768 the file sizes are more than double the high res source (1.13mb - 1.8mb depending on method used).
The source images and thumbnails created are .jpg
Even creating a 299 x 224 thumbnail is 180kb where as if I manually create a thumbnail in GIMP it is 14kb.
I need the images to look good so cannot compromise on quality for size.
I have tried Image.GetThumbnailImage which created a 1.13mb file but I read that it can create unexpected results.
Most articles say to write the code like this article: http://www.codeproject.com/KB/GDI-plus/imageresize.aspx
That gives me a thumbnail of 1.83mb.
Should I be expecting larger file sizes compared to doing the same thing with a desktop application?
I have tried 16 bit instead of 24 and commenting out the "high quality" values but I still cannot get it under 1mb. Any ideas?
Bitmap bmPhoto = new Bitmap(destWidth, destHeight,PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(image.HorizontalResolution,image.VerticalResolution);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;
grPhoto.SmoothingMode = SmoothingMode.HighQuality;
grPhoto.PixelOffsetMode = PixelOffsetMode.HighQuality;
grPhoto.CompositingQuality = CompositingQuality.HighQuality;
EDIT FOR ANSWER
I was lacking compression. My 1024 thumbnail is now 112kb.
Encoder qualityEncoder = Encoder.Quality;
//80L is the compression percentage
EncoderParameter ratio = new EncoderParameter(qualityEncoder, 80L);
// Add the quality parameter to the list
EncoderParameters codecParams = new EncoderParameters(1);
codecParams.Param[0] = ratio;
ImageCodecInfo jpegCodecInfo = GetEncoderInfo("image/jpeg");
bmPhoto.Save(Path.Combine(filepath, RenameImage(filename, appendName, replaceWholeString)), jpegCodecInfo, codecParams);
ImageCodecInfo GetEncoderInfo(string mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for(j = 0; j < encoders.Length; ++j)
{
if(encoders[j].MimeType.ToUpper() == mimeType.ToUpper())
return encoders[j];
}
return null;
}