c# winform 应用编程代码总结 4

14、提取并显示文件包含的图标

        [System.Runtime.InteropServices.DllImport("shell32.dll")]
        private static extern int ExtractIconEx(string lpszFile,int nIconIndex,ref IntPtr phiconLarge,ref IntPtr phiconSmall,int nIcons);
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern int DrawIcon(IntPtr hdc, int x,int y,IntPtr hIcon);
        [System.Runtime.InteropServices.DllImport("user32")]
        private static extern IntPtr GetDC(IntPtr hwnd);

        private void button1_Click(object sender, System.EventArgs e)
        {
            if (this.openFileDialog1.ShowDialog()==DialogResult.OK)
            {
                this.Refresh();
                IntPtr Large, Small;
                int i,nIcons;
                Large=(IntPtr)0;
                Small=(IntPtr)0;
                nIcons=ExtractIconEx(this.openFileDialog1.FileName,-1,ref Large,ref Small,1);
                for(i=0;i<nIcons;i++)
                {
                    ExtractIconEx(this.openFileDialog1.FileName,i,ref Large,ref Small,1);
                    DrawIcon(GetDC(this.Handle),(i/4)*40,(i%4)*40,Large);                    
                }
            }
        }

15、抓取并显示程序中的鼠标

        Graphics g;
        private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            Cursor.Draw(g,new Rectangle(e.X,e.Y,10,10));
        }

        private void Form1_Load(object sender, System.EventArgs e)
        {
            g=this.CreateGraphics();
        }

16、图像的局部放大

        Cursor myCursor=new Cursor("..\\..\\MAGNIFY.CUR");
        Graphics g;
        Image myImage;

        private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            Cursor.Current=Cursors.Default;
        }

        private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            Cursor.Current=myCursor;
            Rectangle sourceRectangle = new Rectangle(e.X-10,e.Y-10,20,20);
            Rectangle destRectangle1 =new Rectangle(300,120,80,80);
            g.DrawImage(myImage,destRectangle1,sourceRectangle,GraphicsUnit.Pixel);
        }

        private void Form1_Load(object sender, System.EventArgs e)
        {
            g=this.pictureBox1.CreateGraphics();
            myImage=this.pictureBox1.Image;
        }

17、对图像进行浮雕处理

        Bitmap bmp;
        private void button1_Click(object sender, System.EventArgs e)
        {
            if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
            {
                bmp=new Bitmap(this.openFileDialog1.FileName);
                for (int i=0;i<bmp.Width-1;i++)
                {
                    for(int j=0;j<bmp.Height-1;j++)
                    {
                        Color Color1=bmp.GetPixel(i,j);
                        Color Color2=bmp.GetPixel(i+1,j+1);
                        int red=Math.Abs(Color1.R-Color2.R+128);
                        int green=Math.Abs(Color1.G-Color2.G+128);
                        int blue=Math.Abs(Color1.B-Color2.B+128);
                        //颜色处理
                        if(red>255)        red=255;
                        if(red<0)        red=0;

                        if(green>255)    green=255;
                        if(green<0)        green=0;

                        if(blue>255)    blue=255;
                        if(blue<0)        blue=0;
                        bmp.SetPixel(i,j,Color.FromArgb(red,green,blue));
                    }
                }
                this.pictureBox1.Image=bmp;
            }
        }

        private void Form1_Load(object sender, System.EventArgs e)
        {
            this.pictureBox1.SizeMode=PictureBoxSizeMode.StretchImage;
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值