zoukankan      html  css  js  c++  java
  • C#图像处理(4):图像的剪裁

    图像的剪裁方法,从中间剪裁返回剪裁后的左右两页,方法实现如下:

     1         /// <summary>
     2         /// 图片裁剪,返回左右两页
     3         /// </summary>
     4         /// <param name="Img">图片</param>
     5         /// <param name="RightMargin">从中间剪裁时左边图片向右偏移量</param>
     6         /// <param name="LeftMargin">从中间剪裁时右边图片向左偏移量</param>
     7         /// <returns>Dictionary</returns>
     8         public Dictionary<string, Bitmap> ImgDiv(Image Img, int RightMargin, int LeftMargin)
     9         {
    10             Dictionary<string, Bitmap> DictImg = new Dictionary<string, Bitmap>();
    11             //获取图片宽高
    12             int Width = Img.Width;
    13             int Height = Img.Height;
    14             //获取图片水平和垂直的分辨率
    15             float dpiX = Img.HorizontalResolution;
    16             float dpiY = Img.VerticalResolution;
    17             //创建一个位图文件
    18             Bitmap BitmapResult = new Bitmap((Width / 2) + RightMargin, Height, PixelFormat.Format24bppRgb);
    19             //设置位图文件的水平和垂直分辨率  与Img一致
    20             BitmapResult.SetResolution(dpiX, dpiY);
    21             //在位图文件上填充一个矩形框
    22             Graphics Grp = Graphics.FromImage(BitmapResult);
    23             System.Drawing.Rectangle Rec = new System.Drawing.Rectangle(0, 0, (Width / 2) + RightMargin, Height);
    24             Grp.DrawImage(Img, 0, 0, Rec, GraphicsUnit.Pixel);
    25             //返回位图文件
    26             Grp.Dispose();
    27             //获取左边图像
    28             DictImg["Left"] = BitmapResult;
    29             //在位图文件上填充一个矩形框
    30             Bitmap BitmapRight = new Bitmap((Width / 2) + LeftMargin, Height, PixelFormat.Format24bppRgb);
    31             BitmapRight.SetResolution(dpiX, dpiY);
    32             Graphics GrpRight = Graphics.FromImage(BitmapRight);
    33             System.Drawing.Rectangle RecRight = new System.Drawing.Rectangle((Width / 2) - LeftMargin, 0, (Width / 2) + LeftMargin, Height);
    34             GrpRight.DrawImage(Img, 0, 0, RecRight, GraphicsUnit.Pixel);
    35             //获取右边图像
    36             DictImg["Right"] = BitmapRight;
    37             GrpRight.Dispose();
    38             GC.Collect();
    39             //返回位图文件
    40             return DictImg;
    41         }
  • 相关阅读:
    41 快速的复制一张表
    4 cdh 5.12 centos 6.10三节点安装
    40 insert语句的锁
    oracle 11g 数据库恢复技术 ---02 控制文件
    05 使用bbed跳过归档恢复数据文件
    Springboot 配置文件与对象之间进行映射之@ConfigurationProperties
    @ConditionalOnProperty来控制Configuration是否生效
    Oracle 服务名/实例名,Service_name 和Sid的区别
    @Value中冒号的作用
    springboot读取配置不存在报错
  • 原文地址:https://www.cnblogs.com/wupeihong/p/3919626.html
Copyright © 2011-2022 走看看