Crop图片的方法

 public static Bitmap CropImage(Bitmap source, Rectangle section)
        {
           //source 参数若来源于Image,一定要用new Bitmap(Image)的形式,而不要强制
         //类型转换,否则截取的图片会模糊且区域不对
            Bitmap bmp = new Bitmap(section.Width, section.Height,PixelFormat.Format32bppRgb);
            bmp.SetResolution(bmp.HorizontalResolution, bmp.VerticalResolution);
          //(96.0F, 96.0F);
          //dpi像素密度  96相当于100%时采样分辨率
            Graphics g = Graphics.FromImage(bmp);
            g.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel);

            return bmp;
        }

 

转载于:https://www.cnblogs.com/nora/p/8064277.html

你可能感兴趣的:(Crop图片的方法)