Image Compress

前言:

         图像压缩的格式目前较常用的有jpeg,png,gif和tiff;

         jpeg是有损压缩,但压缩比很大;

         png是无损压缩,但是压缩比很小,而且用png24才一般不致于图片损失;

         gif也是无损压缩,但是压缩比比png还要小,但是因为是隔行存放数据,解码很快

         tiff也是无损压缩,压缩比可以较容易调节,一般用于高清出版物,因为是目前最复杂的图象保存格式,所以代码操作起来较麻烦;


好了,直接上代码

 static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {

            Bitmap myBitmap;
            ImageCodecInfo myImageCodecInfo;
            Encoder myEncoder;
            EncoderParameter myEncoderParameter;
            EncoderParameters myEncoderParameters;

            // Create a Bitmap object based on a BMP file.
            myBitmap = new Bitmap(@"D:\BOARD\JH3.bmp");

            // Get an ImageCodecInfo object that represents the TIFF codec.
            myImageCodecInfo = GetEncoderInfo("image/tiff");

            // Create an Encoder object based on the GUID
            // for the ColorDepth parameter category.
            myEncoder = Encoder.ColorDepth;

            // Create an EncoderParameters object.
            // An EncoderParameters object has an array of EncoderParameter
            // objects. In this case, there is only one
            // EncoderParameter object in the array.
            myEncoderParameters = new EncoderParameters(1);

            // Save the image with a color depth of 24 bits per pixel.
            myEncoderParameter =
                new EncoderParameter(myEncoder, 24L);
            myEncoderParameters.Param[0] = myEncoderParameter;
            myBitmap.Save(@"d:\Shapes24bpp.tiff", 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;
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值