• c# winform 应用编程代码总结 3


    10、图像的特效显示

            [System.Runtime.InteropServices.DllImport("user32")]
            private static extern IntPtr GetDC(IntPtr hwnd);
            [System.Runtime.InteropServices.DllImport("gdi32")]
            private static extern int BitBlt(IntPtr hDestDC,int x,int y,int nWidth,int nHeight,IntPtr hSrcDC,int xSrc,int ySrc,int dwRop);
            const int SRCCOPY = 0xCC0020;
            
            private void button1_Click(object sender, System.EventArgs e)
            {
                if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
                {
                    Bitmap bmp;
                    bmp=new Bitmap(this.openFileDialog1.FileName);
                    this.pictureBox1.Image=bmp;
                }
            }

            private void button2_Click(object sender, System.EventArgs e)
            {
                int i,j;
                IntPtr hDC1;
                IntPtr hDC2;
                hDC1=GetDC(this.pictureBox1.Handle);
                hDC2=GetDC(this.pictureBox2.Handle);
                for (i=0;i<this.pictureBox1.Width/10;i++)
                {
                    for(j=0;j<10;j++)
                    {
                        BitBlt(hDC2,j*this.pictureBox1.Width/10,0,i+2,this.pictureBox1.Height,hDC1,j*this.pictureBox1.Width/10,0,SRCCOPY);
                    }
                    System.Threading.Thread.Sleep(100); 
                }
            }

    11、显示动画光标

            [DllImport("user32")] 
            private static extern IntPtr SetCursor(IntPtr hCursor); 
            [DllImport("user32")] 
            private static extern IntPtr LoadCursorFromFile(string lpFileName); 
            const int WM_SETCURSOR = 0x0020; 
    
            private void Form1_Load(object sender, System.EventArgs e) 
            { 
                IntPtr hCursor; 
                hCursor=LoadCursorFromFile("..\\..\\stopwtch.ani"); 
                SetCursor(hCursor);     
            } 
    
            protected override void WndProc(ref System.Windows.Forms.Message m) 
            { 
                switch(m.Msg) 
                { 
                    case WM_SETCURSOR: 
                        IntPtr hCursor; 
                        hCursor=LoadCursorFromFile("..\\..\\stopwtch.ani"); 
                        SetCursor(hCursor);     
                        break; 
                    default: 
                        base.WndProc(ref m); 
                        break; 
                } 
            }

    12、缩放时使用插值模式控制图片质量

            private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
            {
                Image image = new Bitmap("..\\..\\test.bmp");
                int width = image.Width;
                int height = image.Height;

                // Draw the image with no shrinking or stretching.
                e.Graphics.DrawImage(
                    image,
                    new Rectangle(10, 10, width, height),  // destination rectangle 
                    0,
                    0,           // upper-left corner of source rectangle
                    width,       // width of source rectangle
                    height,      // height of source rectangle
                    GraphicsUnit.Pixel,
                    null);

                // Shrink the image using low-quality interpolation.
                e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
                e.Graphics.DrawImage(
                    image,
                    new Rectangle(10, 250, (int)(0.6 * width), (int)(0.6*height)), 
                    // destination rectangle
                    0,
                    0,           // upper-left corner of source rectangle
                    width,       // width of source rectangle
                    height,      // height of source rectangle
                    GraphicsUnit.Pixel);

                // Shrink the image using medium-quality interpolation.
                e.Graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
                e.Graphics.DrawImage(
                    image,
                    new Rectangle(150, 250, (int)(0.6 * width), (int)(0.6 * height)),
                    // destination rectangle
                    0,
                    0,           // upper-left corner of source rectangle
                    width,       // width of source rectangle
                    height,      // height of source rectangle
                    GraphicsUnit.Pixel);

                // Shrink the image using high-quality interpolation.
                e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                e.Graphics.DrawImage(
                    image,
                    new Rectangle(290, 250, (int)(0.6 * width), (int)(0.6 * height)),
                    // destination rectangle
                    0,
                    0,           // upper-left corner of source rectangle
                    width,       // width of source rectangle
                    height,      // height of source rectangle
                    GraphicsUnit.Pixel);
            }

    13、轻松实现大图像浏览

                this.pictureBox1.SizeMode=PictureBoxSizeMode.AutoSize;
                if (this.openFileDialog1.ShowDialog()==DialogResult.OK)
                {
                    Bitmap b=new Bitmap(this.openFileDialog1.FileName);
                    this.pictureBox1.Image=b;
                }


  • 相关阅读:
    [找程序员代写推荐]jbpm4.4项目测试源码下载,效果图
    [原]强大的JQuery
    [找程序员代写推荐]SSH+jquery+springScurity权限管理+jasperreport报表+webService调用天气预报+完整分页 整合小型OA项目源码下载
    [找程序员代写推荐]Exception in thread &quot;http-apr-8080-exec-6&quot; java.lang.OutOfMemoryError: PermGen space 解决!
    [原]12-13年学习总结——路上的风景很美
    [找程序员代写推荐]jquery 弹出登陆框,简单易懂!修改密码效果代码
    [找程序员代写推荐]php和apache2的配置
    [找程序员代写推荐]myBatis 基础测试 表关联关系配置 集合 测试
    [找程序员代写推荐]myBatis 基础测试 增 删 改 查 用过hibrenate 之后,感觉很好理解
    JVM运行时数据区域
  • 原文地址:https://www.cnblogs.com/syxchina/p/2197283.html
Copyright © 2020-2023  润新知