Esempio n. 1
0
        public static long CountPixelDifferences(Bitmap frst, Bitmap scnd, double RequiredToPass)
        {
            if (frst.Width != scnd.Width || frst.Height != scnd.Height)
            {
                throw new Exception("Not matching size!");
            }

            Bitmap result = ImageWorks.PaintOn32bpp((Bitmap)frst.Clone());
            Bitmap img1   = ImageWorks.PaintOn32bpp((Bitmap)frst.Clone());
            Bitmap img2   = ImageWorks.PaintOn32bpp((Bitmap)scnd.Clone());

            FastBitmap res = new FastBitmap(result);
            FastBitmap bm1 = new FastBitmap(img1);
            FastBitmap bm2 = new FastBitmap(img2);

            double ValidatePercent   = RequiredToPass;
            long   DifferenceCounter = 0;

            res.Lock();
            bm1.Lock();
            bm2.Lock();

            for (int i = 0; i < result.Width; i++)
            {
                for (int j = 0; j < result.Height; j++)
                {
                    Color c1 = bm1.GetPixel(i, j);
                    Color c2 = bm2.GetPixel(i, j);

                    if (!Differencer.ValidateRGBDIfferencePercent(c1, c2, ValidatePercent))
                    {
                        DifferenceCounter++;
                    }
                }
            }

            res.Unlock();
            bm1.Unlock();
            bm2.Unlock();
            CollectGarbage();

            return(DifferenceCounter);
        }
        public static Bitmap ToGrayScale(this Bitmap bm)
        {
            Bitmap     res = ImageWorks.PaintOn32bpp((Bitmap)bm.Clone());
            FastBitmap fbm = new FastBitmap(res);

            fbm.Lock();

            for (int i = 0; i < fbm.Width; i++)
            {
                for (int j = 0; j < fbm.Height; j++)
                {
                    Color c       = fbm.GetPixel(i, j);
                    int   greyVal = RGBToGreyScale(c);
                    fbm.SetPixel(i, j, Color.FromArgb(greyVal, greyVal, greyVal));
                }
            }

            fbm.Unlock();
            return(res);
        }
Esempio n. 3
0
        public static void FindImage(Bitmap Base, Bitmap LookFor, double requiredToPass, out List <KeyValuePair <Point, Point> > Lpoint)
        {
            Bitmap b = ImageWorks.PaintOn32bpp((Bitmap)Base.Clone());
            Bitmap l = ImageWorks.PaintOn32bpp((Bitmap)LookFor.Clone());

            FastBitmap bs = new FastBitmap(b);
            FastBitmap lf = new FastBitmap(l);

            Lpoint = new List <KeyValuePair <Point, Point> >();

            bs.Lock();
            lf.Lock();

            for (int i = 0; i < Base.Width; i++)
            {
                for (int j = 0; j < Base.Height; j++)
                {
                    int g = i;
                    int t = j;

                    int r = 0;
                    int e = 0;

                    bool preBreaked   = false;
                    long comparedGood = 0;

                    while (Differencer.WiseRGBDifferencePercent(bs.GetPixel(g, t), lf.GetPixel(r, e), requiredToPass))
                    {
                        if (g + 1 == Base.Width || t + 1 == Base.Height || t - j + 1 == lf.Height)
                        {
                            preBreaked = true;
                            break;
                        }
                        comparedGood++;

                        g++;
                        r++;

                        if (g - i == lf.Width)
                        {
                            g = i;
                            t++;
                        }

                        if (r == lf.Width)
                        {
                            r = 0;
                            e++;
                        }
                    }

                    if (!preBreaked)
                    {
                        if ((double)comparedGood >= lf.Width * lf.Height / 100)
                        {
                            Lpoint.Add(new KeyValuePair <Point, Point>(new Point(i, j), new Point(i + lf.Width, j + lf.Height)));
                        }
                    }
                }
            }

            bs.Unlock();
            lf.Unlock();
        }