Create smart-sized thumbnails for a web application

My source images are 2288px x 1712px and 816kb. When I create a thumbnail of size 1024 x 768, the file size is more than twice the size of the high-resolution source (1.13mb - 1.8mb depending on the method used).

Created source images and thumbnails: .jpg

Even creating a 299 x 224 sketch is 180 kb, where, as if I manually created a thumbnail in GIMP, it is 14kb.

I need the images to look good, so they cannot compromise quality for size.

I tried Image.GetThumbnailImage, which created the 1.13mb file, but I read that it can produce unexpected results.

Most articles say write code, as in this article: http://www.codeproject.com/KB/GDI-plus/imageresize.aspx

This gives me a sketch of 1.83mb.

Should I expect larger file sizes compared to the same as with a desktop application?

I tried 16 bits instead of 24 and commented on the "high quality" values, but I still can't 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;

CHANGE ANSWER

I lacked compression. My 1024 sketch 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;    
}
+3
source share
2 answers

The bitmap format is your main concern. It will always be huge compared to other formats. Bitmaps are encoded in length and uncompressed.

- , JPEG - . . , GIF . , FreeImage.

: , JPEG JPEG... Framework.

+1

, (, RLE). PNG, JPG ( JPG2000, ) GIF.

EDIT: JPG, . 1024x768 1 .

+2

Source: https://habr.com/ru/post/1703745/


All Articles