zoukankan      html  css  js  c++  java
  • 图片取色小程序

    应一位网友之邀破解某网站验证码,于是写个小测试程序热热手。

    本小程序功能:在图片上取某一点的颜色
    主要代码如下:

    using System;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using bitmapTest.Properties;

    namespace bitmapTest
    {
        
    public partial class Form1 : Form
        {
            
    public Form1()
            {
                InitializeComponent();
            }

            Bitmap myBitmap;
            
    int cmd = 0;

            
    private void Form1_Load(object sender, EventArgs e)
            {
                pictureBox1.Image 
    = Resources.bfq0002;
                myBitmap 
    = (Bitmap)pictureBox1.Image;
            }
            
    /// <summary>
            
    /// 鼠标取色(移动)
            
    /// </summary>
            private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
            {
                
    int mouseX = e.X;
                
    int mouseY = e.Y;
                txtPoint.Text 
    = "(" + mouseX + "," + mouseY + ")";
                
    if (rbtmutil.Checked)
                {
                    
    //取色
                    try
                    {
                        Color pixelColor 
    = myBitmap.GetPixel(mouseX, mouseY);
                        colorbox.BackColor 
    = pixelColor;
                        txtColorValue.Text 
    = System.Drawing.ColorTranslator.ToHtml(pixelColor);
                    }
                    
    catch
                    { }
                }

                
    //命令
                switch (cmd)
                {
                    
    case 1:  //画线
                        SolidBrush pixelBrush = new SolidBrush(Color.Red);
                        Graphics g 
    = Graphics.FromImage(myBitmap);
                        g.FillRectangle(pixelBrush, mouseX, mouseY, 
    22);
                        pictureBox1.Image 
    = myBitmap;
                        
    break;
                    
    case 2:
                        
    break;
                    
    default:
                        
    break;
                }
            }
            
    /// <summary>
            
    /// 画笔
            
    /// </summary>
            private void btnpen1_Click(object sender, EventArgs e)
            {
                
    if (cmd == 1)
                {
                    cmd 
    = 0;
                    btnpen1.Image 
    = Resources.png_05252;
                    
    this.toolTip1.SetToolTip(this.btnpen1, "单击使用画笔");
                }
                
    else
                {
                    cmd 
    = 1;
                    btnpen1.Image 
    = Resources.png_05253;
                    
    this.toolTip1.SetToolTip(this.btnpen1, "单击禁用画笔");
                }
            }
            
    /// <summary>
            
    /// 恢复
            
    /// </summary>
            private void button1_Click(object sender, EventArgs e)
            {
                pictureBox1.Image 
    = Resources.bfq0002;
                myBitmap 
    = (Bitmap)pictureBox1.Image;
            }
            
    /// <summary>
            
    /// 鼠标取色(单击)
            
    /// </summary>
            private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
            {
                
    //取色
                try
                {
                    Color pixelColor 
    = myBitmap.GetPixel(e.X, e.Y);
                    colorbox.BackColor 
    = pixelColor;
                    txtColorValue.Text 
    = System.Drawing.ColorTranslator.ToHtml(pixelColor);
                }
                
    catch
                { }
            }

        }
    }

    程序界面如下:


    演示版下载: Demo         程序源码:Code

  • 相关阅读:
    python3.5以上版本,typing模块提高代码健壮性
    psutil模块使用
    不懂前后端分离?这篇就够了
    k8s krew 插件管理工具
    metrics-server 安装问题解决
    k8s dashboard 解决secret自建证书导致浏览器访问限制
    创建私有 Gems 源
    windows10 使用WSL(ubuntu系统,xshell连接)
    将 Oracle VirtualBox 中运行的虚拟机导入 VMware Fusion、Workstation 或 Player
    conflunce安装配置
  • 原文地址:https://www.cnblogs.com/tuyile006/p/1094359.html
Copyright © 2011-2022 走看看