The specific code is as follows:
using ; using ; using ; namespace MVC2017_Sample.Controllers { public class DefaultController : Controller { public ActionResult Index() { //Original picture Image img = ("c:\\"); Bitmap map = new Bitmap(img); //The image after mosaic processing Image img2 = AdjustTobMosaic(map, 20); ("c:\\1_bak.jpg", ); return View(); } /// <summary> /// Mosaic processing /// </summary> /// <param name="bitmap"></param> /// <param name="effectWidth"> Range of impact Number of each grid </param> /// <returns></returns> public Bitmap AdjustTobMosaic( bitmap, int effectWidth) { // The most significant difference is to take samples from a certain range. After playing, go directly to the next range. for (int heightOfffset = 0; heightOfffset < ; heightOfffset += effectWidth) { for (int widthOffset = 0; widthOffset < ; widthOffset += effectWidth) { int avgR = 0, avgG = 0, avgB = 0; int blurPixelCount = 0; for (int x = widthOffset; (x < widthOffset + effectWidth && x < ); x++) { for (int y = heightOfffset; (y < heightOfffset + effectWidth && y < ); y++) { pixel = (x, y); avgR += ; avgG += ; avgB += ; blurPixelCount++; } } // Calculate range average avgR = avgR / blurPixelCount; avgG = avgG / blurPixelCount; avgB = avgB / blurPixelCount; // This value is set in all ranges for (int x = widthOffset; (x < widthOffset + effectWidth && x < ); x++) { for (int y = heightOfffset; (y < heightOfffset + effectWidth && y < ); y++) { newColor = (avgR, avgG, avgB); (x, y, newColor); } } } } return bitmap; } } }
Summarize
The above is the implementation code that mosaics the picture to control the degree of blurring. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!