public static Bitmap Pixelate(Bitmap image, int blurSize) { return(ImageProcessor.Pixelate(image, new Rectangle(0, 0, image.Width, image.Height), blurSize)); }
private void HandleImage(string fileName, int effect, int strength) { Image <Bgr, byte> image1 = new Image <Bgr, byte>(fileName); var facesCascade = HttpContext.Current.Server.MapPath("~/haarcascade_frontalface_default.xml"); List <Rectangle> list = FaceDetection.Detect(image1, facesCascade); //this.bkgdWorker.ReportProgress(list.Count, (object)item); Bitmap image2 = image1.ToBitmap(); if (effect != 2) { bool usePixelate = (effect == 1) ? true : false; foreach (Rectangle rectangle in list) { image2 = usePixelate ? ImageProcessor.Pixelate(image2, rectangle, strength) : ImageProcessor.Blur(image2, rectangle, strength); } } string sBluredFileName = "blrd-" + Path.GetFileName(fileName); //string str1 = ".png"; //string str2 = dir + "\\" + text.Substring(0, text.LastIndexOf(".")); //bool flag = true; //int num = 0; //string str3 = ""; //while (flag) //{ // if (File.Exists(str2 + str3 + str1)) // { // ++num; // str3 = "(" + num.ToString() + ")"; // } // else // flag = false; //} image2.Save(Path.GetDirectoryName(fileName) + "\\" + sBluredFileName); image2.Dispose(); image1.Dispose(); File.Delete(fileName); //this.bkgdWorker.ReportProgress(-1, (object)item); }