public static Rectangle FindAutoCropRectangle(Image image, int cropDifference) { Rectangle cropRectangle = Rectangle.Empty; Rectangle currentRectangle = Rectangle.Empty; List <Point> checkPoints = new List <Point>(); // Top Left checkPoints.Add(new Point(0, 0)); // Bottom Left checkPoints.Add(new Point(0, image.Height - 1)); // Top Right checkPoints.Add(new Point(image.Width - 1, 0)); // Bottom Right checkPoints.Add(new Point(image.Width - 1, image.Height - 1)); using (IFastBitmap fastBitmap = FastBitmap.Create((Bitmap)image)) { // find biggest area foreach (Point checkPoint in checkPoints) { currentRectangle = FastBitmapOperator.FindAutoCropRectangle(fastBitmap, checkPoint, cropDifference); if (currentRectangle.Width * currentRectangle.Height > cropRectangle.Width * cropRectangle.Height) { cropRectangle = currentRectangle; } } } return(cropRectangle); }
private void ApplyBoxBlur(Bitmap destinationBitmap, int range) { // We only need one fastbitmap as we use it as source and target (the reading is done for one line H/V, writing after "parsing" one line H/V) using (IFastBitmap fastBitmap = FastBitmap.Create(destinationBitmap)) { FastBitmapOperator.ApplyBoxBlur(fastBitmap, range); } }
public Image Blur(Image sourceImage, int radius) { if (sourceImage == null) { return(sourceImage); } using (IFastBitmap fastBitmap = FastBitmap.CreateCloneOf(sourceImage)) { FastBitmapOperator.ApplyBoxBlur(fastBitmap, radius); Bitmap bmp = new Bitmap(sourceImage.Width, sourceImage.Height, sourceImage.PixelFormat); using (Graphics graphics = Graphics.FromImage(bmp)) { fastBitmap.DrawTo(graphics, Point.Empty); } return(bmp); } }