• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

C#图片剪裁类

OC/C/C++ 水墨上仙 1251次浏览

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


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明C#图片剪裁类
喜欢 (0)
加载中……