public static Bitmap ConvertTo4bpp(System.Drawing.Bitmap img)
        {
            Bitmap   res;
            FIBITMAP dib = FreeImage.CreateFromBitmap(img);

            dib = FreeImage.ConvertColorDepth(dib, FREE_IMAGE_COLOR_DEPTH.FICD_04_BPP, true);
            res = FreeImage.GetBitmap(dib);
            FreeImage.UnloadEx(ref dib);
            return(res);
        }
Esempio n. 2
0
        private void bExample01_Click(object sender, EventArgs e)
        {
            // Load bitmap
            FIBITMAP dib = FreeImage.LoadEx("Sample.jpg");

            // Check success
            if (dib.IsNull)
            {
                MessageBox.Show("Could not load Sample.jpg", "Error");
                return;
            }

            // Check whether bitmap is 24-bit
            if (FreeImage.GetBPP(dib) != 24)
            {
                MessageBox.Show("Sample.jpg is not 24-bit.", "Error");
                FreeImage.UnloadEx(ref dib);
                return;
            }

            // Convert the 24-bit bitmap to 8-bit and forcing the result will be greyscale
            dib = FreeImage.ConvertColorDepth(dib, FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP | FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE, true);

            if (FreeImage.GetBPP(dib) == 8)
            {
                // Convert the FreeImage-Bitmap into a .NET bitmap
                Bitmap bitmap = FreeImage.GetBitmap(dib);

                // Dispose the bitmap of the pictureBox
                if (picBox.Image != null)
                {
                    picBox.Image.Dispose();
                }

                // Assign the bitmap to the picturebox
                picBox.Image = bitmap;
            }

            // Unload source bitmap
            FreeImage.UnloadEx(ref dib);
        }
Esempio n. 3
0
        private void bExample02_Click(object sender, EventArgs e)
        {
            FIBITMAP dib = FreeImage.LoadEx("Sample.jpg");

            // Check success
            if (dib.IsNull)
            {
                MessageBox.Show("Could not load Sample.jpg", "Error");
                return;
            }

            // Convert bitmap to 8 bit
            dib = FreeImage.ConvertColorDepth(dib, FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP, true);

            // Check whether conversion succeeded
            if (FreeImage.GetBPP(dib) != 8)
            {
                MessageBox.Show("Converting Sample.jpg to 8-bit failed.", "Error");
                FreeImage.UnloadEx(ref dib);
                return;
            }

            // Convert the FreeImage-Bitmap into a .NET bitmap
            Bitmap bitmap = FreeImage.GetBitmap(dib);

            // Dispose old bitmap
            if (picBox.Image != null)
            {
                picBox.Image.Dispose();
            }

            // Assign new bitmap
            picBox.Image = bitmap;

            // Unload bitmap
            FreeImage.UnloadEx(ref dib);
        }
Esempio n. 4
0
        void Run()
        {
            Bitmap pic = new Bitmap("Base.png");

            {
                String   fn  = "1bpp-CCITTFAX3";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE | FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_CCITTFAX3);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }
            {
                String   fn  = "1bpp-CCITTFAX4";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE | FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_CCITTFAX4);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }
            {
                String   fn  = "1bpp-DEFLATE";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE | FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_DEFLATE);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }
            {
                String   fn  = "1bpp-LZW";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE | FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_LZW);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }
            {
                String   fn  = "1bpp-PACKBITS";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE | FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_PACKBITS);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }
            {
                String   fn  = "1bpp-ADOBE_DEFLATE";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE | FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_ADOBE_DEFLATE);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }



            {
                String   fn  = "4bpp-DEFLATE";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_04_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_DEFLATE);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }
            {
                String   fn  = "4bpp-LZW";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_04_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_LZW);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }
            {
                String   fn  = "4bpp-PACKBITS";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_04_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_PACKBITS);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }
            {
                String   fn  = "4bpp-ADOBE_DEFLATE";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_04_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_ADOBE_DEFLATE);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }



            {
                String   fn  = "8bpp-DEFLATE";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_DEFLATE);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }
            {
                String   fn  = "8bpp-LZW";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_LZW);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }
            {
                String   fn  = "8bpp-PACKBITS";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_PACKBITS);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }
            {
                String   fn  = "8bpp-ADOBE_DEFLATE";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_ADOBE_DEFLATE);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }
            {
                String   fn  = "8bppGrayscale-JPEG";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP | FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_JPEG);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }



            {
                String   fn  = "24bpp-DEFLATE";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_24_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_DEFLATE);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }
            {
                String   fn  = "24bpp-LZW";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_24_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_LZW);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }
            {
                String   fn  = "24bpp-PACKBITS";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_24_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_PACKBITS);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }
            {
                String   fn  = "24bpp-ADOBE_DEFLATE";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_24_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_ADOBE_DEFLATE);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }
            {
                String   fn  = "24bpp-JPEG";
                FIBITMAP p32 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FIBITMAP p1  = FreeImage.ConvertColorDepth(p32, FREE_IMAGE_COLOR_DEPTH.FICD_24_BPP);
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_JPEG);
                FreeImage.Unload(p1);
                FreeImage.Unload(p32);
            }



            {
                String   fn = "32bpp-DEFLATE";
                FIBITMAP p1 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_DEFLATE);
                FreeImage.Unload(p1);
            }
            {
                String   fn = "32bpp-LZW";
                FIBITMAP p1 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_LZW);
                FreeImage.Unload(p1);
            }
            {
                String   fn = "32bpp-PACKBITS";
                FIBITMAP p1 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_PACKBITS);
                FreeImage.Unload(p1);
            }
            {
                String   fn = "32bpp-ADOBE_DEFLATE";
                FIBITMAP p1 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_ADOBE_DEFLATE);
                FreeImage.Unload(p1);
            }



            {
                String   fn = "8bppGrayscale-JPEG-ExtraSamples";
                FIBITMAP p1 = FreeImage.CreateFromBitmap(Draws(fn, pic));
                //FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, p1, fn + ".tif", FREE_IMAGE_SAVE_FLAGS.TIFF_LZW);
                FreeImage.Unload(p1);
            }


            StringWriter wr = new StringWriter();

            foreach (String fp in Directory.GetFiles(".", "*.tif"))
            {
                wr.WriteLine(Resources.Templ
                             .Replace("*", Path.GetFileName(fp))
                             .Replace("?", Path.GetFileName(fp))
                             );
            }
            File.WriteAllText("Templ.txt", wr.ToString());
        }