zoukankan      html  css  js  c++  java
  • 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;
                }


  • 相关阅读:
    spring -项目功能介绍
    【HQL】分页查询 、对象导航查询、外置命名查询、连接查询、查询过滤器、统计查询
    【HQL】属性查询、条件查询
    【HQL】hibernate查询语言hql
    Hibernate- 表联系
    struts 配置过程 -一个计算器程序
    【DRP】-JSTL核心库 c:out标签
    .NET 使用sock5做代理(不是搭建服务端)
    重磅新闻!昨日阿里云发布首款云电脑“无影”,到底如何呢?
    C#如何实现获取电脑硬件相关的配置信息呢?
  • 原文地址:https://www.cnblogs.com/syxchina/p/2197283.html
Copyright © 2011-2022 走看看