public Bitmap Clone(PixelFormat pixelFormat) { List <Color> palette = null; // indexed formats require 2 passes - one more pass to determines colors for palette beforehand if (pixelFormat.IsIndexed()) { var quantizer = new DistinctSelectionQuantizer(); quantizer.Prepare(this); // Pass: scan ImageBuffer.ProcessPerPixel(this, null, ParallelTaskCount, (passIndex, pixel) => { var color = pixel.GetColor(); quantizer.AddColor(color, pixel.X, pixel.Y); return(true); }); // determines palette palette = quantizer.GetPalette(pixelFormat.GetColorCount()); } // Pass: apply Image result; ImageBuffer.TransformImagePerPixel(this, pixelFormat, palette, out result, null, ParallelTaskCount, (passIndex, sourcePixel, targetPixel) => { var color = sourcePixel.GetColor(); targetPixel.SetColor(color, _quantizer); return(true); }); return((Bitmap)result); }
private ColorPalette GetColours(Image sourceImage, PictureBox picture) { IColorQuantizer activeQuantizer = new DistinctSelectionQuantizer(); IColorCache activeColorCache = new EuclideanDistanceColorCache(); ((BaseColorCacheQuantizer)activeQuantizer).ChangeCacheProvider(activeColorCache); ((BaseColorCache)activeColorCache).ChangeColorModel(ColorModel.RedGreenBlue); Int32 parallelTaskCount = 8; TaskScheduler uiScheduler = TaskScheduler.FromCurrentSynchronizationContext(); Image targetImage = ImageBuffer.QuantizeImage(sourceImage, activeQuantizer, null, 2, parallelTaskCount); picture.Image = targetImage; return(targetImage.Palette); }
public Bitmap Clone(PixelFormat pixelFormat) { List<Color> palette = null; // indexed formats require 2 passes - one more pass to determines colors for palette beforehand if (pixelFormat.IsIndexed()) { var quantizer = new DistinctSelectionQuantizer(); quantizer.Prepare(this); // Pass: scan ImageBuffer.ProcessPerPixel(this, null, ParallelTaskCount, (passIndex, pixel) => { var color = pixel.GetColor(); quantizer.AddColor(color, pixel.X, pixel.Y); return true; }); // determines palette palette = quantizer.GetPalette(pixelFormat.GetColorCount()); } // Pass: apply Image result; ImageBuffer.TransformImagePerPixel(this, pixelFormat, palette, out result, null, ParallelTaskCount, (passIndex, sourcePixel, targetPixel) => { var color = sourcePixel.GetColor(); targetPixel.SetColor(color, _quantizer); return true; }); return (Bitmap)result; }