日期:2014-05-18  浏览次数:21179 次

怎么从一张有多个小图标的图片中得到每个图标的集合
如题,
就一个图片上面有很多小图标按规格排列,现在想得到这里边的所有图标集,
用C#该怎么弄呢

------解决方案--------------------
C# code
        /// <summary>
        /// 剪切
        /// </summary>
        /// <param name="b">原始图</param>
        /// <param name="startX">原始图上的起始坐标X值</param>
        /// <param name="startY">原始图上的起始坐标Y值</param>
        /// <param name="iWidth">需要的宽度</param>
        /// <param name="iHeight">需要的高度</param>
        /// <returns>结果图</returns>
        public 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;
            }

            Graphics g = null;

            try
            {
                Bitmap bmpOut = new Bitmap(iWidth, iHeight, PixelFormat.Format32bppArgb);

                g = Graphics.FromImage(bmpOut);
                g.DrawImage(b, new Rectangle(0, 0, iWidth, iHeight), new Rectangle(startX, startY, iWidth, iHeight), GraphicsUnit.Pixel);

                return bmpOut;
            }
            catch
            {
                return null;
            }
            finally
            {
                if (g != null)
                    g.Dispose();
            }


        }