Пример #1
0
        private static byte[] EncodeNxIcon(Bitmap icon, uint nxIconMaxSize)
        {
            if (icon.RawFormat.Guid == ImageFormat.Jpeg.Guid)
            {
                Rectangle  rect        = new Rectangle(0, 0, icon.Width, icon.Height);
                BitmapData bitmapData  = icon.LockBits(rect, ImageLockMode.ReadOnly, icon.PixelFormat);
                byte[]     destination = new byte[bitmapData.Stride * bitmapData.Height];
                Marshal.Copy(bitmapData.Scan0, destination, 0, destination.Length);
                return(destination);
            }
            int  num1    = 100;
            int  quality = num1;
            int  num2    = 0;
            uint num3    = nxIconMaxSize;

            do
            {
                if ((long)IconConverter.Encode(icon, quality).Length > (long)num3)
                {
                    quality = (quality + num2) / 2;
                }
                else
                {
                    num2    = quality;
                    quality = (quality + num1) / 2;
                }
            }while (quality != num2);
            return(IconConverter.Encode(icon, quality));
        }
Пример #2
0
 private static byte[] EncodeRawIcon(Bitmap icon)
 {
     return(IconConverter.Encode(icon, 98));
 }