示例#1
0
        /// <summary>
        /// Encode the bitmap into 1, 4, or 8 bits per pixel
        /// </summary>
        /// <param name="imgData">Image Data</param>
        private static void CompressBitmap(ImageData imgData)
        {
            using (Bitmap imageRaw = new Bitmap(imgData.BmpFilePath))
            {
                using (BitmapEncoder imageCompressed = new BitmapEncoder())
                {
                    Bitmap bmpFile = imageCompressed.Encode(imageRaw, 4);

                    // Delete any old file
                    if (File.Exists(imgData.PngFilePath))
                    {
                        File.Delete(imgData.PngFilePath);
                    }

                    // Save the file in the new path
                    bmpFile.Save(imgData.PngFilePath);
                }
            }
        }