• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

学习FotoVision进行C#colorMatrix对图片的处理:亮度调整抓屏翻转随鼠标画矩形 ...

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

0.FotoVision下载地址

http://www.microsoft.com/downloads/details.aspx?FamilyId=D4738DCA-E95C-4D4F-BF32-00A865006C73&displaylang=en

 

 1.图片亮度处理

private void trackBar1_ValueChanged(object sender, EventArgs e)
{
    //this.numericUpDown1.Value = this.trackBar1.Value;

    int percent = this.trackBar1.Value;
    Single v = 0.006F * percent;
    Single[][] matrix = {
        new Single[] { 1, 0, 0, 0, 0 },
        new Single[] { 0, 1, 0, 0, 0 },
        new Single[] { 0, 0, 1, 0, 0 },
        new Single[] { 0, 0, 0, 1, 0 },
        new Single[] { v, v, v, 0, 1 }
    };
    System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix(matrix);
    System.Drawing.Imaging.ImageAttributes attr = new System.Drawing.Imaging.ImageAttributes();
    attr.SetColorMatrix(cm);
    //Image tmp
    Image tmp = Image.FromFile(@"F:\\ImageManager\images\1.jpg");
    Graphics g = Graphics.FromImage(tmp);
    try
    {
        Rectangle destRect = new Rectangle(0, 0, tmp.Width, tmp.Height);
        g.DrawImage(tmp, destRect, 0, 0, tmp.Width, tmp.Height, GraphicsUnit.Pixel, attr);
    }
    finally
    {
        g.Dispose();
    }
    this.pictureBox1.Image = tmp;
}

 

2.抓屏将生成的图片显示在pictureBox
private void button1_Click(object sender, EventArgs e)
 {
     Image myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
     Graphics g = Graphics.FromImage(myImage);
     g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height));
     IntPtr dc1 = g.GetHdc();
     g.ReleaseHdc(dc1);
     g.Dispose();
     this.pictureBox1.Image = myImage;
}

3.翻转
private void button3_Click(object sender, EventArgs e)
{
    Image tmp = this.pictureBox1.Image;
    tmp.RotateFlip(RotateFlipType.Rotate90FlipNone);
    this.pictureBox1.Image = tmp;
}

 

4.跟随鼠标在 pictureBox的图片上画矩形
private int intStartX = 0;
private int intStartY = 0;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
    if (isMouseDraw)
    {
        isMouseDraw = false;
        //MessageBox.Show("禁用随鼠标画图");
    }
    else
    {
        isMouseDraw = true;
        //MessageBox.Show("启用随鼠标画图");
    }

    if (isMouseDraw)
    {
        intStartX = e.X;
        intStartY = e.Y;
    }
    else
    {
        intStartX = 0;
        intStartY = 0;
    }
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
    if (isMouseDraw)
    {
        try
        {
            Image tmp = Image.FromFile(@"F:\\ImageManager\images\1.jpg");
            Graphics g = Graphics.FromImage(tmp);
            Brush brush = new SolidBrush(Color.Red);
            Pen pen = new Pen(brush, 1);
            pen.DashStyle = DashStyle.Solid;
            g.DrawRectangle(pen, new Rectangle(intStartX > e.X ? e.X : intStartX, intStartY > e.Y ? e.Y : intStartY, Math.Abs(e.X - intStartX), Math.Abs(e.Y - intStartY)));
            g.Dispose();

            this.pictureBox1.Image = tmp;
        }
        catch (Exception ex)
        {
            ex.ToString();
        }
    }
}


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
JS、C#去除html标签发布时间:2022-07-10
下一篇:
C#http请求带请求头部分发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap