国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

winfrom-圖片拆分成多塊

2019-11-10 22:57:42
字體:
供稿:網(wǎng)友

先在panel容器(長寬為300)中繪制一個宮格,比如下面這樣:

PRivate void Form1_Load(object sender, EventArgs e)        {            this.InitRandomPictureBox();        }                private void InitRandomPictureBox()        {            this.pnl_Random.Controls.Clear();            for (int i = 0; i < this.ImgNumbers; i++)            {                for (int j = 0; j < this.ImgNumbers; j++)                {                    PictureBox pic = new PictureBox();                    pic.Location = new Point(j * this.SideLength, i * this.SideLength);                    pic.Size = new Size(this.SideLength, this.SideLength);                    pic.Visible = true;                    pic.BorderStyle = BorderStyle.FixedSingle;                    this.pnl_Random.Controls.Add(pic);                }            }        }
/// <summary>        /// 每個方向上要切割成的塊數(shù)        /// </summary>        private int ImgNumbers        {            get            {                return 3;            }        }        /// <summary>        /// 要切割成的正方形圖片邊長        /// </summary>        private int SideLength        {            get            {                return 300 / this.ImgNumbers; //300:panel容器大小            }        }//圖片切割:
/// <summary>        /// 將圖片切割成小圖片,圖片順序為先水平后垂直        /// </summary>        /// <param name="cx">水平方向多少個圖片</param>        ///<param name="cy">垂直方向多少個圖片</param>        public static Image[] SplitToSmallImages(this Image fromImage, int cx, int cy)        {            Image[] imgs = new Image[cx * cy];            int nWidth = fromImage.Width / cx;            int nHeight = fromImage.Height / cy;            Bitmap image = new Bitmap(nWidth, nHeight);            Graphics graphics = Graphics.FromImage(image);            for (int i = 0; i < cy; i++)            {                for (int j = 0; j < cx; j++)                {                    graphics.DrawImage(fromImage, 0, 0, new Rectangle(j * nWidth, i * nHeight, nWidth, nHeight), GraphicsUnit.Pixel);                    Image img = Image.FromHbitmap(image.GetHbitmap());                    int idx = j + i * cx;                    img.Tag = idx;                    imgs[idx] = img;                }            }            return imgs;        }將切好的圖片隨機(jī)排序然后放入到容器中:
var tmp = this._splitImages.OrderBy(p => Guid.NewGuid()).ToList();            for (int i = 0; i < tmp.Count; i++)            {                this._splitPictureBoxes[i].Image = tmp[i];            }


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 阳西县| 崇左市| 汤原县| 北碚区| 罗江县| 赤峰市| 册亨县| 盐源县| 阿勒泰市| 遂平县| 长沙市| 长乐市| 樟树市| 庆元县| 阜南县| 定襄县| 大渡口区| 丹凤县| 祁阳县| 新巴尔虎左旗| 惠州市| 邹城市| 卢氏县| 方正县| 富顺县| 宜宾县| 固原市| 尚义县| 历史| 四平市| 斗六市| 崇信县| 阿坝| 买车| 桃源县| 温泉县| 五河县| 义乌市| 安福县| 朝阳县| 广昌县|