asp.net C # image into a circle, and save it to the local

// image into a circular

     private Image CutEllipse(Image img, Rectangle rec, Size size, string imgSavePath)
        {
            Bitmap bitmap = new Bitmap(size.Width, size.Height);
            using (Graphics g = Graphics.FromImage(bitmap))
            {
                using (TextureBrush br = new TextureBrush(img, System.Drawing.Drawing2D.WrapMode.Clamp, rec))
                {
                    br.ScaleTransform(bitmap.Width / (float)rec.Width, bitmap.Height / (float)rec.Height);
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    g.FillEllipse(br, new Rectangle(Point.Empty, size));
                }
            }          
            bitmap.Save(imgSavePath, System.Drawing.Imaging.ImageFormat.Png);
            return null;
        }

// method call

     = imgpath " ~ / submitImages / 20180913094627.png " ; 
        Image Image = Image.FromFile (HttpContext.Current.Server.MapPath (imgpath));        // determine whether the picture already exists, if present, remove the 
        IF (! File.Exists ( imgSavePath)) 
        { 
            // File.Delete (Path.GetFullPath (imgSavePath)); // delete the presence
             // image into a circular shape, and saves it to 
            CutEllipse (image, new new the Rectangle ( 0 , 0 , 200 is , 200 is ) , new new Size ( 200 is , 200 is  ), imgSavePath);
        }

 

 

 

private Image CutEllipse(Image img, Rectangle rec, Size size, string imgSavePath)        {            Bitmap bitmap = new Bitmap(size.Width, size.Height);            using (Graphics g = Graphics.FromImage(bitmap))            {                using (TextureBrush br = new TextureBrush(img, System.Drawing.Drawing2D.WrapMode.Clamp, rec))                {                    br.ScaleTransform(bitmap.Width / (float)rec.Width, bitmap.Height / (float)rec.Height);                    //br.ScaleTransform(bitmap.Width , bitmap.Height);                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;                    g.FillEllipse(br, new Rectangle(Point.Empty, size));                }            }                      bitmap.Save(imgSavePath, System.Drawing.Imaging.ImageFormat.Png);            return null;        }

Guess you like

Origin www.cnblogs.com/ciel-shan/p/10908721.html