/// <summary> /// Constructs a BilinearResizer. /// </summary> /// <param name="old">The old PixelsArray to resize.</param> /// <param name="res">The result PixelsArray to resize to.</param> public BilinearResizer(PixelsArray old, PixelsArray res) { this.old = old; this.res = res; x_ratio = ((float)(old.Width - 1)) / res.Width; y_ratio = ((float)(old.Height - 1)) / res.Height; }
/// <summary> /// Rotates this ManipulableImage 90° to the right. /// </summary> /// <param name="pixels">The new array that will be used to store /// this ManipulableImage's pixels.</param> public void RotateRight(int[] pixels) { PixelsArray old = this.pixels; this.pixels = new PixelsArray(old.Width, old.Height, pixels); for (int row = 0; row < Height; row++) { for (int col = 0; col < Width; col++) { this[row, col] = old[old.Height - 1 - col, row]; } } }
/// <summary> /// Constructs a ManipulableImage. /// </summary> /// <param name="height">The height of the image.</param> /// <param name="width">The width of the image.</param> /// <param name="pixels">The ARGB color values for each of /// the image's pixels in row-major order.</param> public ManipulableImage(int height, int width, int[] pixels) { this.pixels = new PixelsArray(height, width, pixels); }
/// <summary> /// Resizes this ManipulableImage. /// </summary> /// <param name="height">The height to which to resize /// this ManipulableImage.</param> /// <param name="width">The width to which to resize /// this ManipulableImage.</param> /// <param name="pixels">The new array that will be used to store /// this ManipulableImage's pixels.</param> public void Resize(int height, int width, int[] pixels) { PixelsArray old = this.pixels; this.pixels = new PixelsArray(height, width, pixels); for (int row = 0; row < Height; row++) { for (int col = 0; col < Width; col++) { this[row, col] = old[ (int)((double)row / Height * old.Height), (int)((double)col / Width * old.Width)]; } } }
/// <summary> /// Crops this ManipulableImage to the specified Rectangle. /// </summary> /// <param name="rect">The Rectangle to crop to.</param> /// <param name="pixels">The new array that will be used to store /// this ManipulableImage's pixels.</param> public void Crop(PixRect rect, int[] pixels) { for (int row = rect.Row; row < rect.Row + rect.Height; row++) { Buffer.BlockCopy( Pixels, sizeof(int) * (row * Width + rect.Col), pixels, sizeof(int) * (row - rect.Row) * rect.Width, sizeof(int) * rect.Width); } this.pixels = new PixelsArray(rect.Height, rect.Width, pixels); }
/// <summary> /// Resizes this ManipulableImage using bilinear filtering. /// </summary> /// <param name="height">The height to which to resize /// this ManipulableImage.</param> /// <param name="width">The width to which to resize /// this ManipulableImage.</param> /// <param name="pixels">The new array that will be used to store /// this ManipulableImage's pixels.</param> public void BilinearResize(int height, int width, int[] pixels) { PixelsArray res = new PixelsArray(height, width, pixels); BilinearResizer br = new BilinearResizer(this.pixels, res); br.Resize(); this.pixels = res; }