public static Bitmap GetTransformedImage(WorkerData workerData) { ArgbColor[] pixelData; Size size; IPixelTransform transform; IErrorDiffusion dither; transform = workerData.Transform; dither = workerData.Dither; using (Bitmap image = workerData.Image) { size = image.Size; pixelData = image.GetPixelsFrom32BitArgbImage(); } if (dither != null && dither.Prescan) { // perform the dithering on the source data before // it is transformed ProcessPixels(pixelData, size, null, dither); dither = null; } // scan each pixel, apply a transform the pixel // and then dither it ProcessPixels(pixelData, size, transform, dither); // create the final bitmap return(pixelData.ToBitmap(size)); }
public static Bitmap RequestImageTransform(Bitmap image, IPixelTransform transform, IErrorDiffusion ditherer) { WorkerData workerData; if (image.PixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb) { using (Bitmap tmp = image) { image = tmp.Copy(); } } workerData = new WorkerData { Image = image, Transform = transform, Dither = ditherer }; return(backgroundWorker_RunWorkerCompleted(null, new RunWorkerCompletedEventArgs(GetTransformedImage(workerData), null, false))); }