欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C# 將透明圖片的非透明區(qū)域轉(zhuǎn)換成Region的實(shí)例代碼

 更新時(shí)間:2013年10月08日 14:33:32   作者:  
以下代碼實(shí)現(xiàn)將一張帶透明度的png圖片的非透明部分轉(zhuǎn)換成Region輸出的方法,有需要的朋友可以參考一下

需要設(shè)置允許不安全代碼.....項(xiàng)目->屬性->生成->允許不安全代碼

復(fù)制代碼 代碼如下:

/// <summary>
        /// 根據(jù)圖片得到一個(gè)圖片非透明部分的區(qū)域
      /// </summary>
        /// <param name="bckImage"></param>
        /// <returns></returns>
        private unsafe Region GetRegion(Bitmap bckImage)
        {
            GraphicsPath path = new GraphicsPath();
            int w = bckImage.Width;
            int h = bckImage.Height;
            BitmapData bckdata = null;
            try
            {
                bckdata = bckImage.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                uint* bckInt = (uint*)bckdata.Scan0;
                for (int j = 0; j < h; j++)
                {
                    for (int i = 0; i < w; i++)
                    {
                        if ((*bckInt & 0xff000000) != 0)
                        {
                            path.AddRectangle(new Rectangle(i, j, 1, 1));
                        }
                        bckInt++;
                    }
                }
                bckImage.UnlockBits(bckdata); bckdata = null;
            }
            catch
            {
                if (bckdata != null)
                {
                    bckImage.UnlockBits(bckdata);
                    bckdata = null;
                }
            }
            Region region = new System.Drawing.Region(path);
            path.Dispose(); path = null;
            return region;
        }

相關(guān)文章

最新評(píng)論