Пример #1
0
        //private string getSuffix(ExportFileType type) {

        //}

        private DibMd loadFile(string srcPath, int icoSize)
        {
            string srcSuffix = Path.GetExtension(srcPath).ToLower();

            FIBITMAP dib;

            try {
                switch (srcSuffix)
                {
                case ".ico": {
                    dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_ICO, srcPath, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
                    break;
                }

                case ".bmp": {
                    dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_BMP, srcPath, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
                    break;
                }

                case ".jpg": {
                    dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, srcPath, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
                    break;
                }

                case ".png": {
                    dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_PNG, srcPath, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
                    break;
                }

                default: {
                    Bitmap img = FileIcon.getIcon(srcPath, icoSize);
                    if (img == null)
                    {
                        return(null);
                    }
                    dib = FreeImage.CreateFromBitmap(img);
                    break;
                    //return;
                }
                }
                return(new DibMd(dib));
            } catch (Exception) { }

            return(null);
        }
Пример #2
0
        private void convert(string srcPath, string dstPath, int icoSize, int bpp)
        {
            string srcSuffix = Path.GetExtension(srcPath).ToLower();
            string dstSuffix = Path.GetExtension(dstPath).ToLower();

            //bool isDir = Directory.Exists(srcPath);

            // save
            try {
                FIBITMAP dib;
                switch (srcSuffix)
                {
                case ".ico": {
                    dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_ICO, srcPath, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
                    break;
                }

                case ".bmp": {
                    dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_BMP, srcPath, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
                    break;
                }

                case ".jpg": {
                    dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, srcPath, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
                    break;
                }

                case ".png": {
                    dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_PNG, srcPath, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
                    break;
                }

                default: {
                    Bitmap img = FileIcon.getIcon(srcPath, icoSize);
                    if (img == null)
                    {
                        return;
                    }
                    dib = FreeImage.CreateFromBitmap(img);
                    break;
                    //return;
                }
                }
                //FIBITMAP dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_PNG, srcPath, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
                uint width  = FreeImage.GetWidth(dib);
                uint height = FreeImage.GetHeight(dib);
                //FIBITMAP dibTmp = FreeImage.Rescale(dib, icoSize, icoSize, FREE_IMAGE_FILTER.FILTER_BICUBIC);

                FIBITMAP dibOut = formatImage(dib, icoSize, bpp);

                FREE_IMAGE_FORMAT     format = FREE_IMAGE_FORMAT.FIF_ICO;
                FREE_IMAGE_SAVE_FLAGS flag   = FREE_IMAGE_SAVE_FLAGS.BMP_SAVE_RLE;
                switch (dstSuffix)
                {
                case ".png": format = FREE_IMAGE_FORMAT.FIF_PNG; flag = FREE_IMAGE_SAVE_FLAGS.PNG_Z_DEFAULT_COMPRESSION; break;

                case ".jpg": format = FREE_IMAGE_FORMAT.FIF_JPEG; flag = FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYGOOD; break;

                case ".bmp": format = FREE_IMAGE_FORMAT.FIF_BMP; flag = FREE_IMAGE_SAVE_FLAGS.BMP_SAVE_RLE; break;

                case ".ico":
                default: break;
                }
                FreeImage.Save(format, dibOut, dstPath, flag);
                //bool isOk = FreeImage.Save(FREE_IMAGE_FORMAT.FIF_PNG, dibOut, dstPath + ".png", FREE_IMAGE_SAVE_FLAGS.PNG_INTERLACED);
                FreeImage.Unload(dibOut);
                FreeImage.Unload(dib);
            } catch (Exception ex) { Debug.WriteLine(ex.ToString()); }
        }