publicclass PixelateEffect : IEffect {publicstring Name { get { return"Pixelate"; } }public PixelateEffect() { } ///<summary>/// Processes a bitmap and returns a new processed WriteabelBitmap.///</summary>///<param name="input">The input bitmap.</param>///<returns>The result of WriteabelBitmap processing.</returns>public WriteableBitmap Process(WriteableBitmap input) {// Prepare some variablesvar width = input.PixelWidth;var height = input.PixelHeight;return Process(input.Pixels, width, height, 100).ToWriteableBitmap(width, height); }publicint[] Process(int[] inputPixels, int width, int height) {returnthis.Process(inputPixels, width, height, 10); }publicint[] Process(int[] inputPixels, int width, int height, int blockSize) {// y, xint[,] pixelated = inputPixels.To2DArray(width, height);// Loop across 2D arrayfor (int bX = 0; bX < width; bX += blockSize) {for (int bY = 0; bY < height; bY += blockSize) {// Find adjusted block widthint blockX = bX + blockSize <= width ? blockSize : width - bX;int blockY = bY + blockSize <= height ? blockSize : height - bY;// Get centre colourint pixel = pixelated[bY + blockY / 2, bX + blockX / 2];// Apply colour to blockfor (int x = bX; x < bX + blockX; x++)for (int y = bY; y < bY + blockY; y++) pixelated[y, x] = pixel; } }return pixelated.ToArray(); } }
↧
New Post: PixelateEffect
↧