Home>

The specific code is as follows:

using system.drawing;
using system.drawing.imaging;
using system.web.mvc;
namespace mvc2017_sample.controllers
{
 public class defaultcontroller:controller
 {
  public actionresult index ()
  {
   //Original picture
   image img=image.fromfile ("c:\\ 1.jpg");
   bitmap map=new bitmap (img);
   //Mosaic processed image image img2=Adjusttobmosaic (map, 20);
   img2.save ("c:\\ 1_bak.jpg", imageformat.jpeg);
   return view ();
  }
  ///<summary>
  ///Mosaic processing
  ///</summary>
  ///<param name="bitmap"></param>
  ///<param name="effectwidth">Affect range Number of each grid</param>
  ///<returns></returns>
  public bitmap adjusttobmosaic (system.drawing.bitmap bitmap, int effectwidth)
  {
   //The biggest difference is to sample according to a certain range and go directly to the next range after playing
   for (int heightofffset=0;heightofffset<bitmap.height;heightofffset +=effectwidth)
   {
    for (int widthoffset=0;widthoffset<bitmap.width;widthoffset +=effectwidth)
    {
     int avgr=0, avgg=0, avgb=0;
     int blurpixelcount=0;
     for (int x=widthoffset;(x<widthoffset + effectwidth&&x<bitmap.width);x ++)
     {
      for (int y=heightofffset;(y<heightofffset + effectwidth&&y<bitmap.height);y ++)
      {
       system.drawing.color pixel=bitmap.getpixel (x, y);
       avgr +=pixel.r;
       avgg +=pixel.g;
       avgb +=pixel.b;
       blurpixelcount ++;
      }
     }
     //Calculate range average
     avgr=avgr/blurpixelcount;
     avgg=avgg/blurpixelcount;
     avgb=avgb/blurpixelcount;
     //set this value in all ranges
     for (int x=widthoffset;(x<widthoffset + effectwidth&&x<bitmap.width);x ++)
     {
      for (int y=heightofffset;(y<heightofffset + effectwidth&&y<bitmap.height);y ++)
      {
       system.drawing.color newcolor=system.drawing.color.fromargb (avgr, avgg, avgb);
       bitmap.setpixel (x, y, newcolor);
      }
     }
    }
   }
   return bitmap;
  }
 }
}

to sum up

c
  • Previous Implementation code based on Mybatis plus automatic code generator
  • Next Perfectly solve the problem that Pycharm cannot import packages Unresolved reference