读书人

简单的画图

发布时间: 2012-06-03 16:59:40 作者: rapoo

求一个简单的画图。
有一张图片 大小是1200x1200
现在要把这个图片的左边切掉50 右边也切掉50 就成了1100x1200了。
注意 是切掉, 不是略缩。
麻烦各位了

[解决办法]

C# code
   public static Bitmap Cut(Bitmap b, int StartX, int StartY, int iWidth, int iHeight)        {            if (b == null)            {                return null;            }            int w = b.Width;            int h = b.Height;            if (StartX >= w || StartY >= h)            {                return null;            }            if (StartX + iWidth > w)            {                iWidth = w - StartX;            }            if (StartY + iHeight > h)            {                iHeight = h - StartY;            }            try            {                Bitmap bmpOut = new Bitmap(iWidth, iHeight, PixelFormat.Format24bppRgb);                Graphics g = Graphics.FromImage(bmpOut);                g.DrawImage(b, new Rectangle(0, 0, iWidth, iHeight), new Rectangle(StartX, StartY, iWidth, iHeight), GraphicsUnit.Pixel);                g.Dispose();                return bmpOut;            }            catch            {                return null;            }
[解决办法]
b是原始1200*1200图像
C# code
            Bitmap bmp = new Bitmap(1100, 1200);            Graphics g = Graphics.FromImage(bmp);            g.DrawImage(b, 50, 0, 1100, 1200); 

读书人网 >C#

热点推荐