void DrawSquare(FastBitmap source, int x, int y, int width, int height) { for (int py = 0; py < height; py++) { for (int px = 0; px < width; px++) { source.SetPixel(x + px, y + py, Color.Blue); } } }
Bitmap Crop(Bitmap source, Rectangle rectangle) { var fastSource = new FastBitmap(source); var croppedImage = new Bitmap(rectangle.Width, rectangle.Height); var fastCroppedImage = new FastBitmap(croppedImage); fastCroppedImage.LockImage(); fastSource.LockImage(); for (int y = rectangle.Y, startY = rectangle.Y, endY = rectangle.Y + rectangle.Height; y < endY; y++) { for (int x = rectangle.X, startX = rectangle.X, endX = rectangle.X + rectangle.Width; x < endX; x++) { var pixel = fastSource.GetPixel(x, y); fastCroppedImage.SetPixel(x - startX, y - startY, pixel); } } fastCroppedImage.UnlockImage(); fastSource.UnlockImage(); return(croppedImage); }