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;
        }

 

posted on 2017-12-19 10:33  笨nora  阅读(1381)  评论(0编辑  收藏  举报