C #. Image.GetThumbnailImage increasing file size

1

I have an image of 320x320.

When I use Image.GetThumbnailImage it generates an image of 180x180.

Only the file size of 320x300 is 10k, the Thumbnail file size is 52k ...

I wanted it to be at least equal, does anyone have any suggestions?

EDIT:

I have an image on the disk and open it like this:

Image image = new Bitmap(caminhoenomenodisco);

After that I simply do the Thumbnail like this:

Image nova = image.GetThumbnailImage(180, 180, null, new IntPtr());

EDIT:

Actually, the disk image is 24 bit-high, and the new image is saved with 32 bit depth.

I do not know how to generate the Thumbnail with 24 of intensity.

    
asked by anonymous 06.05.2015 / 15:25

1 answer

0

The bit depth must be different. The default Windows (currently) is 32-bit.

Open Bitmap specifying a bit depth :

var bmp = new Bitmap(320, 320, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

Format24bppRbg specifies 24-bit depth. See here the full list of available formats .

The depth (or depth) of bits can be seen in the properties of the file (right click > Properties), Details tab:

Foryourspecificcase,youneedtorecodethefiletoanotherbitdepth.Thisisdoneusinga Encoder of type ColorDepth . In this last link there is an example that I change below to reflect your reality:

using System;
using System.Drawing;
using System.Drawing.Imaging;
class Example_SetColorDepth
{
    public static void Main()
    {
        Bitmap myBitmap;
        ImageCodecInfo myImageCodecInfo;
        Encoder myEncoder;
        EncoderParameter myEncoderParameter;
        EncoderParameters myEncoderParameters;

        // Abre o Bitmap
        myBitmap = new Bitmap(@"C:\Documents and Settings\All Users\Documents\meubmp.bmp");

        // Cria um objeto para o Encoder baseado no MIME type
        myImageCodecInfo = GetEncoderInfo("image/bmp");

        // Cria o Encoder propriamente dito
        myEncoder = Encoder.ColorDepth;

        // Parametrização
        myEncoderParameters = new EncoderParameters(1);

        // Processo de conversão de profundidade de pixels
        myEncoderParameter =
            new EncoderParameter(myEncoder, 24L);
        myEncoderParameters.Param[0] = myEncoderParameter;
        myBitmap.Save("meubmp_24bits.bmp", myImageCodecInfo, myEncoderParameters);
    }

    private static ImageCodecInfo GetEncoderInfo(String mimeType)
    {
        int j;
        ImageCodecInfo[] encoders;
        encoders = ImageCodecInfo.GetImageEncoders();
        for(j = 0; j < encoders.Length; ++j)
        {
            if(encoders[j].MimeType == mimeType)
                return encoders[j];
        }
        return null;
    }
}

The full list of MIME types is here .

    
06.05.2015 / 16:26