Program.cs
/// <summary>
/// Convert a PNG file to 8-bit color
/// Note that it's responsibility of the caller to handle exceptions
/// </summary>
/// <exception cref="System.Exception">Catch all error for a number of scenarios</exception>
/// <param name="filePath"></param>
Convert a PNG file to 8-bit color
Note that it's responsibility of the caller to handle exceptions
Convert a PNG file to 8 - bit color Note that it ' s responsibility of the caller to handle exceptions
public static void To8BitPngByFile(string filePath, bool checkColorDepth = true)
        {
            if (checkColorDepth)
            {
                if (IsPng8BitColorDepth(filePath))
                {
                    return;
                }
            }
            var quantizer = new WuQuantizer();
            Image quantized = null;
            try
            {
                var bitmap = new Bitmap(filePath);
                quantized = quantizer.QuantizeImage(bitmap);
                bitmap.Dispose();
                quantized.Save(filePath, ImageFormat.Png);
            } finally
            {
                if (quantized != null)
                {
                    quantized.Dispose();
                }
            }
        }
public static void To8BitPngByFile ( string filePath , bool checkColorDepth = true ) { if ( checkColorDepth ) { if ( IsPng8BitColorDepth ( filePath ) ) { return ; } } var quantizer = new WuQuantizer ( ) ; Image quantized = null ; try { var bitmap = new Bitmap ( filePath ) ; quantized = quantizer . QuantizeImage ( bitmap ) ; bitmap . Dispose ( ) ; quantized . Save ( filePath , ImageFormat . Png ) ; } finally { if ( quantized != null ) { quantized . Dispose ( ) ; } } }
Convert a PNG file to 8-bit color
Note that it's responsibility of the caller to handle exceptions
Convert a PNG file to 8 - bit color Note that it ' s responsibility of the caller to handle exceptions
// check to see if the file is already 8 bit // no need to convert - it's already 8 bit. // release the original bitmap so that it can be overwriten
Catch all error for a number of scenarios
Catch all error for a number of scenarios
filePath
string
None
checkColorDepth
bool