C#. Image.Getthumbnailimage increasing file size

Asked

Viewed 387 times

1

I have a picture of 320x320.

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

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

I wish he was at least the same, someone has some suggestion?

EDIT:

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

Image image = new Bitmap(caminhoenomenodisco);

After that I simply do Thumbnail like this:

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

EDIT:

Actually the disk image is at 24 bit intensity and the new image is saved at 32 intensity.

I don’t know how to generate Thumbnail with 24 of intensity.

1 answer

0


Bit depth must be different. Windows default (currently) is 32 bits.

Open the Bitmap specifying a bit depth:

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

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

Bit depth (or intensity) can be seen in the file properties (right click > Properties), tab Details:

Bit Depth

For your specific case, you need to recode the file to another bit depth. This is done using a Encoder of the kind 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.

  • I made a change to the question, I didn’t understand how I can open a disk file passing bit depth, the files I have are 24 of intensity yes. How would I do that in the code I edited in the question?

  • @user3517631 I edited the answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.