原始Bitmap /// 开始坐标X /// 开始坐标Y ///
 | 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
bdnp
9年前发布

C#图片剪裁类

public class ImageCut  {      /// <summary>         /// 剪裁 -- 用GDI+      /// </summary>      /// <param name="b">原始Bitmap</param>      /// <param name="StartX">开始坐标X</param>      /// <param name="StartY">开始坐标Y</param>         /// <param name="iWidth">宽度</param>      /// <param name="iHeight">高度</param>      /// <returns>剪裁后的Bitmap</returns>         public Bitmap KiCut(Bitmap b)      {          if (b == null)          {              return null;          }              int w = b.Width;          int h = b.Height;              if (X >= w || Y >= h)          {              return null;          }              if (X + Width > w)          {              Width = w - X;          }              if (Y + Height > h)          {              Height = h - Y;          }              try          {              Bitmap bmpOut = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);                  Graphics g = Graphics.FromImage(bmpOut);              g.DrawImage(b, new Rectangle(0, 0, Width, Height), new Rectangle(X, Y, Width, Height), GraphicsUnit.Pixel);              g.Dispose();                  return bmpOut;          }          catch          {              return null;          }      }          public int X = 0;      public int Y = 0;      public int Width = 120;      public int Height = 120;      public ImageCut(int x, int y, int width, int heigth)      {          X = x;          Y = y;          Width = width;          Height = heigth;      }  }