C#图象动态显示的方法

       /// <summary>
        /// 左到右拉伸
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLeftToRight_Click(object sender, EventArgs e)
        {
            int iWidth = this.pictureBox1.Width;
            int iHeight = this.pictureBox1.Height;
           
            Graphics g = this.pictureBox1.CreateGraphics();
            g.Clear(Color.Gray);
            for (int x = 0; x <= iWidth; x++)
            {
                g.DrawImage(bmp, 0, 0, x, iHeight);
            }
        }

        /// <summary>
        /// 上到下拉伸
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpToDown_Click(object sender, EventArgs e)
        {
            int iWidth = this.pictureBox1.Width;
            int iHeight = this.pictureBox1.Height;

            Graphics g = this.pictureBox1.CreateGraphics();
            g.Clear(Color.Gray);
            for (int y = 0; y <= iHeight; y++)
            {
                g.DrawImage(bmp, 0, 0, iWidth, y);
            }
        }

        /// <summary>
        /// 四周扩散
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExtend_Click(object sender, EventArgs e)
        {
            int iWidth = this.pictureBox1.Width;
            int iHeight = this.pictureBox1.Height;
           
            Graphics g = this.pictureBox1.CreateGraphics();
            g.Clear(Color.Gray); //初始为全灰色
            for (int x = 0; x <= iWidth / 2; x++)
            {
                Rectangle DestRect = new Rectangle(iWidth / 2 - x,iHeight / 2 - x, 2 * x, 2 * x);
                Rectangle SrcRect = new Rectangle(0, 0,bmp.Width, bmp.Height);
                g.DrawImage(bmp, DestRect, SrcRect,GraphicsUnit.Pixel);
            }
        }

        /// <summary>
        /// 反转图像
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBack_Click(object sender, EventArgs e)
        {
            int iWidth = this.pictureBox1.Width;  
            int iHeight = this.pictureBox1.Height;
           
            Graphics g = this.pictureBox1.CreateGraphics();
            g.Clear(Color.Gray);
            for (int x = -iWidth / 2; x <= iWidth / 2; x++)
            {
                Rectangle DestRect = new Rectangle(0, iHeight / 2 - x,iWidth, 2 * x);
                Rectangle SrcRect = new Rectangle(0, 0, bmp.Width, bmp.Height);
                g.DrawImage(bmp, DestRect, SrcRect, GraphicsUnit.Pixel);
            }
        }

        /// <summary>
        /// 两边拉伸
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBothSide_Click(object sender, EventArgs e)
        {
            int iWidth = this.pictureBox1.Width;
            int iHeight = this.pictureBox1.Height;
           
            Graphics g = this.pictureBox1.CreateGraphics();
            g.Clear(Color.Gray);
            for (int y = 0; y <= iWidth / 2; y++)
            {
                Rectangle DestRect = new Rectangle(iWidth / 2 - y, 0,2 * y, iHeight);
                Rectangle SrcRect = new Rectangle(0, 0, bmp.Width, bmp.Height);
                g.DrawImage(bmp, DestRect, SrcRect, GraphicsUnit.Pixel);
            }
        }

        /// <summary>
        /// 上下对接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpDownConnect_Click(object sender, EventArgs e)
        {
            int iWidth = this.pictureBox1.Width;  
            int iHeight = this.pictureBox1.Height;
           
            Graphics g = this.pictureBox1.CreateGraphics();
            g.Clear(Color.Gray);
            Bitmap bitmap = new Bitmap(iWidth, iHeight);
            int x = 0;
            while (x <= iHeight / 2)
            {
                for (int i = 0; i <= iWidth - 1; i++)
                {
                    bitmap.SetPixel(i, x,bmp.GetPixel(i, x));
                }
                for (int i = 0; i <= iWidth - 1; i++)
                {
                    bitmap.SetPixel(i, iHeight - x - 1,bmp.GetPixel(i, iHeight - x - 1));
                }
                x++;
                this.pictureBox1.Refresh();
                this.pictureBox1.Image = bitmap;
            } 
        }

        /// <summary>
        /// 左右对接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLeftRightConnect_Click(object sender, EventArgs e)
        {
            int iWidth = this.pictureBox1.Width;
            int iHeight = this.pictureBox1.Height;
           
            Graphics g = this.pictureBox1.CreateGraphics();
            g.Clear(Color.Gray);
            Bitmap bitmap = new Bitmap(iWidth, iHeight);
            int x = 0;
            while (x <= iWidth / 2)
            {
                for (int i = 0; i <= iHeight - 1; i++)
                {
                    bitmap.SetPixel(x, i, bmp.GetPixel(x, i));
                }
                for (int i = 0; i <= iHeight - 1; i++)
                {
                    bitmap.SetPixel(iWidth - x - 1, i,bmp.GetPixel(iWidth - x - 1, i));
                }
                x++;
                this.pictureBox1.Refresh();
                this.pictureBox1.Image = bitmap;
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值