public static BlockCopy ( |
||
src | ||
srcOffset | int | |
dest | ||
destOffset | int | |
count | int | |
리턴 | void |
public static BitmapHolder ToCropped(BitmapHolder source, int x, int y, int width, int height) { var srcWidth = source.Width; var srcHeight = source.Height; // Clamp to boundaries if (x < 0) { x = 0; } if (x + width > srcWidth) { width = srcWidth - x; } if (y < 0) { y = 0; } if (y + height > srcHeight) { height = srcHeight - y; } // Copy the pixels line by line using fast BlockCopy var result = new byte[width * height * 4]; for (var line = 0; line < height; line++) { var srcOff = ((y + line) * srcWidth + x) * ColorExtensions.SizeOfArgb; var dstOff = line * width * ColorExtensions.SizeOfArgb; Helpers.BlockCopy(source.PixelData, srcOff, result, dstOff, width * ColorExtensions.SizeOfArgb); } return(new BitmapHolder(result, width, height)); }
public static BitmapHolder ToCropped(BitmapHolder source, int x, int y, int width, int height) { int width2 = source.Width; int height2 = source.Height; if (x < 0) { x = 0; } if (x + width > width2) { width = width2 - x; } if (y < 0) { y = 0; } if (y + height > height2) { height = height2 - y; } byte[] array = new byte[width * height * 4]; for (int i = 0; i < height; i++) { int srcOffset = ((y + i) * width2 + x) * 4; int destOffset = i * width * 4; Helpers.BlockCopy(source.PixelData, srcOffset, array, destOffset, width * 4); } return(new BitmapHolder(array, width, height)); }
public static BitmapHolder ToCropped(BitmapHolder source, double zoomFactor, double xOffset, double yOffset, double cropWidthRatio, double cropHeightRatio) { double num = source.Width; double num2 = source.Height; double num3 = num; double num4 = num2; double num5 = cropWidthRatio / cropHeightRatio; double num6 = num / num2; if (num6 > num5) { num3 = cropWidthRatio * num2 / cropHeightRatio; } else if (num6 < num5) { num4 = cropHeightRatio * num / cropWidthRatio; } xOffset *= num3; yOffset *= num4; num3 /= zoomFactor; num4 /= zoomFactor; float num7 = (float)((num - num3) / 2.0 + xOffset); float num8 = (float)((num2 - num4) / 2.0 + yOffset); if (num7 < 0f) { num7 = 0f; } if (num8 < 0f) { num8 = 0f; } if ((double)num7 + num3 > num) { num7 = (float)(num - num3); } if ((double)num8 + num4 > num2) { num8 = (float)(num2 - num4); } int num9 = (int)num3; int num10 = (int)num4; byte[] array = new byte[num9 * num10 * 4]; for (int i = 0; i < num10; i++) { int srcOffset = (((int)num8 + i) * source.Width + (int)num7) * 4; int destOffset = i * num9 * 4; Helpers.BlockCopy(source.PixelData, srcOffset, array, destOffset, num9 * 4); } return(new BitmapHolder(array, num9, num10)); }
public static void ToCropped(BitmapHolder source, int x, int y, int width, int height) { var srcWidth = source.Width; var srcHeight = source.Height; // If the rectangle is completely out of the bitmap if (x > srcWidth || y > srcHeight) { return; } // Clamp to boundaries if (x < 0) { x = 0; } if (x + width > srcWidth) { width = srcWidth - x; } if (y < 0) { y = 0; } if (y + height > srcHeight) { height = srcHeight - y; } // Copy the pixels line by line using fast BlockCopy var result = new int[width * height]; for (var line = 0; line < height; line++) { var srcOff = ((y + line) * srcWidth + x) * Helpers.SizeOfArgb; var dstOff = line * width * Helpers.SizeOfArgb; Helpers.BlockCopy(source.Pixels, srcOff, result, dstOff, width * Helpers.SizeOfArgb); } source.SetPixels(result, width, height); }
public static BitmapHolder ToCropped(BitmapHolder source, double zoomFactor, double xOffset, double yOffset, double cropWidthRatio, double cropHeightRatio) { double sourceWidth = source.Width; double sourceHeight = source.Height; double desiredWidth = sourceWidth; double desiredHeight = sourceHeight; double desiredRatio = cropWidthRatio / cropHeightRatio; double currentRatio = sourceWidth / sourceHeight; if (currentRatio > desiredRatio) { desiredWidth = (cropWidthRatio * sourceHeight / cropHeightRatio); } else if (currentRatio < desiredRatio) { desiredHeight = (cropHeightRatio * sourceWidth / cropWidthRatio); } xOffset = xOffset * desiredWidth; yOffset = yOffset * desiredHeight; desiredWidth = desiredWidth / zoomFactor; desiredHeight = desiredHeight / zoomFactor; float cropX = (float)(((sourceWidth - desiredWidth) / 2) + xOffset); float cropY = (float)(((sourceHeight - desiredHeight) / 2) + yOffset); if (cropX < 0) { cropX = 0; } if (cropY < 0) { cropY = 0; } if (cropX + desiredWidth > sourceWidth) { cropX = (float)(sourceWidth - desiredWidth); } if (cropY + desiredHeight > sourceHeight) { cropY = (float)(sourceHeight - desiredHeight); } int width = (int)desiredWidth; int height = (int)desiredHeight; // Copy the pixels line by line using fast BlockCopy var result = new byte[width * height * 4]; for (var line = 0; line < height; line++) { var srcOff = (((int)cropY + line) * source.Width + (int)cropX) * ColorExtensions.SizeOfArgb; var dstOff = line * width * ColorExtensions.SizeOfArgb; Helpers.BlockCopy(source.PixelData, srcOff, result, dstOff, width * ColorExtensions.SizeOfArgb); } return(new BitmapHolder(result, width, height)); }