当前位置:编程学习 > C#/ASP.NET >>

C# GDI+ 图形图像编程

一般的图像特技,如百叶窗,模仿ppt里的特技。都是c++写的。用于LED屏显示的。请问用c#写可以么,有相关经验的人,请推荐一点资料,和书籍。 --------------------编程问答-------------------- 可以,不过绘图效率更要多加考虑 --------------------编程问答-------------------- 我以前学C#时写的几个效果,抛砖引玉

[code=C#0]
        /// <summary>
        /// 水平百叶窗
        /// </summary>
        /// <param name="ImageName"></param>
        private void Effect2(string ImageName)
        {
            int N = 10;//百叶窗数目
            Bitmap sbmp = (Bitmap)(Image.FromFile(ImageName));
            Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g0 = Graphics.FromImage(bmp);
            g0.DrawImage(sbmp, 0, 0, bmp.Width, bmp.Height);
            sbmp.Dispose();
            Graphics g = pictureBox1.CreateGraphics();
            int h = pictureBox1.Height  / N;
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    g.DrawImage(bmp, new Rectangle(0, j * h + i, bmp.Width, 1), new Rectangle(0, j * h + i, bmp.Width, 1), GraphicsUnit.Pixel);
                    System.Threading.Thread.Sleep(10);
                }
            }
            bmp.Dispose();
        }

        /// <summary>
        /// 垂直百叶窗
        /// </summary>
        /// <param name="ImageName"></param>
        private void Effect1(string ImageName)
        {
            int N = 10;//百叶窗数目
            Bitmap sbmp =(Bitmap)(Image.FromFile(ImageName));
            Bitmap bmp=new Bitmap (pictureBox1 .Width ,pictureBox1 .Height );
            Graphics g0=Graphics .FromImage (bmp );
            g0.DrawImage (sbmp ,0,0,bmp.Width ,bmp.Height );
            sbmp.Dispose() ;
            Graphics g = pictureBox1.CreateGraphics();
            int w=pictureBox1 .Width / N;
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    g.DrawImage(bmp, new Rectangle(j * w + i, 0, 1, bmp.Height), new Rectangle(j * w + i, 0, 1, bmp.Height),GraphicsUnit.Pixel );
                    System.Threading.Thread.Sleep(10);
                }
             }
            bmp.Dispose();
        }



[/code] --------------------编程问答--------------------

        /// <summary>
        /// 从左拉入
        /// </summary>
        /// <param name="ImageName"></param>
        private void Effect3(string ImageName)
        {
            Bitmap sbmp = (Bitmap)(Image.FromFile(ImageName));
            Bitmap nbmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g0 = Graphics.FromImage(nbmp);
            g0.DrawImage(sbmp, 0, 0, nbmp.Width, nbmp.Height);
            sbmp.Dispose();
            Graphics g = pictureBox1.CreateGraphics();

            for (int i = 0; i <= nbmp.Width; i++)
            {
                g.DrawImage(nbmp, new Rectangle(0, 0, i , nbmp.Height), new Rectangle(0, 0, nbmp.Width, nbmp.Height), GraphicsUnit.Pixel);
                g.DrawImage(obmp, new Rectangle(i, 0, nbmp.Width -i, nbmp.Height), new Rectangle(0, 0, obmp.Width, obmp.Height), GraphicsUnit.Pixel);
                System.Threading.Thread.Sleep (10);
            }
            nbmp.Dispose();
        }


        /// <summary>
        /// 从右拉入
        /// </summary>
        /// <param name="ImageName"></param>
        private void Effect4(string ImageName)
        {
            Bitmap sbmp = (Bitmap)(Image.FromFile(ImageName));
            Bitmap nbmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g0 = Graphics.FromImage(nbmp);
            g0.DrawImage(sbmp, 0, 0, nbmp.Width, nbmp.Height);
            sbmp.Dispose();
            Graphics g = pictureBox1.CreateGraphics();

            for (int i = 0; i <= nbmp.Width; i++)
            {
                g.DrawImage(nbmp, new Rectangle(nbmp.Width -i, 0, i , nbmp.Height), new Rectangle(0, 0, nbmp.Width, nbmp.Height), GraphicsUnit.Pixel);
                g.DrawImage(obmp, new Rectangle(0, 0, nbmp.Width - i, nbmp.Height), new Rectangle(0, 0, obmp.Width, obmp.Height), GraphicsUnit.Pixel);
                System.Threading.Thread.Sleep(10);
            }
            nbmp.Dispose();
        }


        /// <summary>
        /// 从上拉入
        /// </summary>
        /// <param name="ImageName"></param>
        private void Effect5(string ImageName)
        {
            Bitmap sbmp = (Bitmap)(Image.FromFile(ImageName));
            Bitmap nbmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g0 = Graphics.FromImage(nbmp);
            g0.DrawImage(sbmp, 0, 0, nbmp.Width, nbmp.Height);
            sbmp.Dispose();
            Graphics g = pictureBox1.CreateGraphics();

            for (int i = 0; i <= nbmp.Height; i++)
            {
                g.DrawImage(nbmp, new Rectangle(0, 0 , nbmp .Width , i), new Rectangle(0, 0, nbmp.Width, nbmp.Height), GraphicsUnit.Pixel);
                g.DrawImage(obmp, new Rectangle(0, i, nbmp.Width, nbmp.Height-i), new Rectangle(0, 0, obmp.Width, obmp.Height), GraphicsUnit.Pixel);
                System.Threading.Thread.Sleep(10);
            }
            nbmp.Dispose();
        }


        /// <summary>
        /// 从下拉入
        /// </summary>
        /// <param name="ImageName"></param>
        private void Effect6(string ImageName)
        {
            Bitmap sbmp = (Bitmap)(Image.FromFile(ImageName));
            Bitmap nbmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g0 = Graphics.FromImage(nbmp);
            g0.DrawImage(sbmp, 0, 0, nbmp.Width, nbmp.Height);
            sbmp.Dispose();
            Graphics g = pictureBox1.CreateGraphics();

            for (int i = 0; i <= nbmp.Height; i++)
            {
                g.DrawImage(nbmp, new Rectangle(0, nbmp.Height - i, nbmp.Width, i ), new Rectangle(0, 0, nbmp.Width, nbmp.Height), GraphicsUnit.Pixel);
                g.DrawImage(obmp, new Rectangle(0, 0, nbmp.Width, nbmp.Height - i), new Rectangle(0, 0, obmp.Width, obmp.Height), GraphicsUnit.Pixel);
                System.Threading.Thread.Sleep(10);
            }
            nbmp.Dispose();
        }

        /// <summary>
        /// 从左移入
        /// </summary>
        /// <param name="ImageName"></param>
        private void Effect7(string ImageName)
        {
            Bitmap sbmp = (Bitmap)(Image.FromFile(ImageName));
            Bitmap nbmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g0 = Graphics.FromImage(nbmp);
            g0.DrawImage(sbmp, 0, 0, nbmp.Width, nbmp.Height);
            sbmp.Dispose();
            Graphics g = pictureBox1.CreateGraphics();

            for (int i = 0; i <= nbmp.Width; i++)
            {
                g.DrawImage(nbmp, new Rectangle(i-nbmp .Width , 0, nbmp .Width , nbmp.Height), new Rectangle(0, 0, nbmp.Width, nbmp.Height), GraphicsUnit.Pixel);
                g.DrawImage(obmp, new Rectangle(i, 0, nbmp.Width ,nbmp.Height), new Rectangle(0, 0, obmp.Width, obmp.Height), GraphicsUnit.Pixel);
                System.Threading.Thread.Sleep(10);
            }
            nbmp.Dispose();
        }


        /// <summary>
        /// 从右移入
        /// </summary>
        /// <param name="ImageName"></param>
        private void Effect8(string ImageName)
        {
            Bitmap sbmp = (Bitmap)(Image.FromFile(ImageName));
            Bitmap nbmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g0 = Graphics.FromImage(nbmp);
            g0.DrawImage(sbmp, 0, 0, nbmp.Width, nbmp.Height);
            sbmp.Dispose();
            Graphics g = pictureBox1.CreateGraphics();

            for (int i = 0; i <= nbmp.Width; i++)
            {
                g.DrawImage(nbmp, new Rectangle(nbmp.Width - i, 0, nbmp .Width , nbmp.Height), new Rectangle(0, 0, nbmp.Width, nbmp.Height), GraphicsUnit.Pixel);
                g.DrawImage(obmp, new Rectangle(0-i, 0, nbmp.Width, nbmp.Height), new Rectangle(0, 0, obmp.Width, obmp.Height), GraphicsUnit.Pixel);
                System.Threading.Thread.Sleep(10);
            }
            nbmp.Dispose();
        }

        /// <summary>
        /// 从上移入
        /// </summary>
        /// <param name="ImageName"></param>
        private void Effect9(string ImageName)
        {
            Bitmap sbmp = (Bitmap)(Image.FromFile(ImageName));
            Bitmap nbmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g0 = Graphics.FromImage(nbmp);
            g0.DrawImage(sbmp, 0, 0, nbmp.Width, nbmp.Height);
            sbmp.Dispose();
            Graphics g = pictureBox1.CreateGraphics();

            for (int i = 0; i <= nbmp.Height; i++)
            {
                g.DrawImage(nbmp, new Rectangle(0, i-nbmp.Height , nbmp.Width, nbmp.Height ), new Rectangle(0, 0, nbmp.Width, nbmp.Height), GraphicsUnit.Pixel);
                g.DrawImage(obmp, new Rectangle(0, i, nbmp.Width, nbmp.Height ), new Rectangle(0, 0, obmp.Width, obmp.Height), GraphicsUnit.Pixel);
                System.Threading.Thread.Sleep(10);
            }
            nbmp.Dispose();
        }


        /// <summary>
        /// 从下移入
        /// </summary>
        /// <param name="ImageName"></param>
        private void Effect10(string ImageName)
        {
            Bitmap sbmp = (Bitmap)(Image.FromFile(ImageName));
            Bitmap nbmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g0 = Graphics.FromImage(nbmp);
            g0.DrawImage(sbmp, 0, 0, nbmp.Width, nbmp.Height);
            sbmp.Dispose();
            Graphics g = pictureBox1.CreateGraphics();

            for (int i = 0; i <= nbmp.Height; i++)
            {
                g.DrawImage(nbmp, new Rectangle(0, nbmp.Height - i, nbmp.Width, nbmp.Height ), new Rectangle(0, 0, nbmp.Width, nbmp.Height), GraphicsUnit.Pixel);
                g.DrawImage(obmp, new Rectangle(0, 0-i, nbmp.Width, nbmp.Height ), new Rectangle(0, 0, obmp.Width, obmp.Height), GraphicsUnit.Pixel);
                System.Threading.Thread.Sleep(10);
            }
            nbmp.Dispose();
        }
--------------------编程问答-------------------- 谢谢,还能推荐书籍。不能光看你们的啊。要写特技多了。。 --------------------编程问答-------------------- 书籍问别人吧,我从来没看过书。 --------------------编程问答-------------------- 我通常是想做什么就去做 卡在那里看哪里
百度一下 你就知道
看书没必要吧 实践是编程的唯一真理 --------------------编程问答-------------------- 如果是做页面的,在上面实现这些效果很好的;
如果在Winform里做的话,我基本用的是第三方控件;

我买了本明日科技的C# 范例宝典,里面有,但是觉得效果不是很好;
你需要的话可以把里面的例子源代码给你 --------------------编程问答-------------------- 啊,好啊,我的QQ642730170
麻烦加我啊。 --------------------编程问答-------------------- 等晚上回家了,我白天上班时是用不了QQ的 --------------------编程问答-------------------- 我学过又忘了,赶紧去复习下
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,