Ejemplo n.º 1
0
        private void DoTestLabMouse()
        {
            if (picBmp == null)
            {
                return;
            }

            DontDoTestLab = true;

            //This code get the RGB value from a point or a region from the picture(picBmp is a Bitmap)

            lcmsRGBColor pixel = (chkRange.Checked)
                                                                        ? GetAvgRGBFromBitmap(picBmp, picX, picY, (int)nupRange.Value)
                                                                        : new lcmsRGBColor(picBmp.GetPixel(picX, picY));

            rgbColor.FromColor(pixel);



            tbRed.Value   = Convert.ToInt32(pixel.R);
            tbGreen.Value = Convert.ToInt32(pixel.G);
            tbBlue.Value  = Convert.ToInt32(pixel.B);



            TestLabDBL();

            DontDoTestLab = false;
        }
Ejemplo n.º 2
0
        private lcmsRGBColor GetAvgRGBFromBitmap(Bitmap picture, int xC, int yC, int rangeInit)
        {
            if (picture == null)
            {
                return(null);
            }

            // 1 inch = 25.4 mm
            double verticalResolution   = picture.VerticalResolution / 25.4;           //Pixel per mm
            double horizontalResolution = picture.HorizontalResolution / 25.4;         //Pixel per mm

            int rangeX = Convert.ToInt32(rangeInit * horizontalResolution);
            int rangeY = Convert.ToInt32(rangeInit * verticalResolution);

            if (chkMM.Checked)
            {
                rangeX = rangeInit;
                rangeY = rangeInit;
            }

            var avgColor = new lcmsRGBColor();

            int r = 0;
            int g = 0;
            int b = 0;

            int x1 = CorrectRangeValue(xC - rangeX, 0, picture.Width - 1);
            int y1 = CorrectRangeValue(yC - rangeY, 0, picture.Height - 1);
            int x2 = CorrectRangeValue(xC + rangeX, 0, picture.Width - 1);
            int y2 = CorrectRangeValue(yC - rangeY, 0, picture.Height - 1);

            int pixelCount = 0;

            for (int y = y1; y <= y2; y++)
            {
                for (int x = x1; x <= x2; x++)
                {
                    var pixel = picture.GetPixel(x, y);
                    r += pixel.R;
                    g += pixel.G;
                    b += pixel.B;
                    pixelCount++;
                }
            }

            avgColor.R = (double)r / pixelCount;
            avgColor.G = (double)g / pixelCount;
            avgColor.B = (double)b / pixelCount;

            return(avgColor);
        }