AoiRgbControl.cs 4.5 KB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; 
using AOI;
using Asa.Theme;

namespace AccAOI.control
{
    public partial class AoiRgbControl : ABaseControl
    {
        public AoiRgbControl()
        {
            InitializeComponent();
        }
        private AoiMethodRgb methodRgb = null;
        public override void ShowAoiInfo()
        {
            if (this.AoiInfo is AoiMethodRgb)
            {
                methodRgb = (AoiMethodRgb)AoiInfo;
                //txtMinR.Text = methodRgb.minR.ToString();
                //txtMaxR.Text = methodRgb.maxR.ToString();
                //txtMinG.Text = methodRgb.minG.ToString();
               // txtMaxG.Text = methodRgb.maxG.ToString();
              //  txtMaxB.Text = methodRgb.maxB.ToString();
              //  txtMinB.Text = methodRgb.minB.ToString();
                SetTbValue(tbMinR, methodRgb.minR);
                SetTbValue(tbMaxR, methodRgb.maxR);
                SetTbValue(tbMinG, methodRgb.minG);
                SetTbValue(tbMaxG, methodRgb.maxG);
                SetTbValue(tbMaxB, methodRgb.maxB);
                SetTbValue(tbMinB, methodRgb.minB);
                txtminRate.Text = methodRgb.minRate.ToString();
                txtmaxRate.Text = methodRgb.maxRate.ToString();
            }

        }
        public override AoiMethod GetAoiInfo()
        {
            if (this.AoiInfo is AoiMethodRgb)
            {
                methodRgb = (AoiMethodRgb)AoiInfo;

                methodRgb.minR = FormUtil.GetIntValue(txtMinR);
                methodRgb.maxR = FormUtil.GetIntValue(txtMaxR);
                methodRgb.minG = FormUtil.GetIntValue(txtMinG);
                methodRgb.maxG = FormUtil.GetIntValue(txtMaxG);
                methodRgb.maxB = FormUtil.GetIntValue(txtMaxB);
                methodRgb.minB = FormUtil.GetIntValue(txtMinB);
                SetTbValue(tbMinR, methodRgb.minR);
                SetTbValue(tbMaxR, methodRgb.maxR);
                SetTbValue(tbMinG, methodRgb.minG);
                SetTbValue(tbMaxG, methodRgb.maxG);
                SetTbValue(tbMaxB, methodRgb.maxB);
                SetTbValue(tbMinB, methodRgb.minB);
                methodRgb.minRate = FormUtil.GetIntValue(txtminRate);
                methodRgb.maxRate = FormUtil.GetIntValue(txtmaxRate);
                if (currPath != null)
                {
                    methodRgb.RoiPath = currPath;
                }
                AoiInfo = methodRgb;
            }
            return AoiInfo;
        }



        public override void UpdateImage()
        {
            if (BaseImage == null)
            {
                return;
            }
            GetAoiInfo();
            Image cutImg = null;
            Image dstCutImg = null;
            float rate = methodRgb.GetRate(BaseImage, out cutImg, out dstCutImg);
            
            txtRate.Text = rate.ToString();
            this.aoiImage.Image = cutImg;
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            UpdateImage();
        }

        private void txtMinR_TextChanged(object sender, EventArgs e)
        {
            UpdateImage();
        }

        private void tbMinR_ValueChanged(object sender, EventArgs e)
        {
            SetText(txtMinR, tbMinR.Value);
        }
       
        private void tbMaxR_ValueChanged(object sender, EventArgs e)
        {
            SetText(txtMaxR, tbMaxR.Value);
        }

        private void tbMinG_ValueChanged(object sender, EventArgs e)
        { 
            SetText(txtMinG, tbMinG.Value);
        }

        private void tbMaxG_ValueChanged(object sender, EventArgs e)
        {
            SetText(txtMaxG, tbMaxG.Value);
        }

        private void tbMinB_ValueChanged(object sender, EventArgs e)
        {
            SetText(txtMinB, tbMinB.Value);
        }

        private void tbMaxB_ValueChanged(object sender, EventArgs e)
        {
            SetText(txtMaxB, tbMaxB.Value);
        }

        private void SetText(FlatText text, int value)
        {
            if (text.Text.ToString().Equals(value.ToString()))
            {
                return;
            }
            text.Text = value.ToString();
        }
        private void SetTbValue(TrackBar tb, int value)
        {
            if (tb.Value.Equals(value.ToString()))
            {
                return;
            }
            tb.Value = value;
        }
    }
}