Example #1
0
        public unsafe static void miniaturaHSI(Bitmap src, Bitmap h, Bitmap s, Bitmap i)
        {
            int        W          = src.Width;
            int        H          = src.Height;
            BitmapData bmpDataSrc = src.LockBits(new Rectangle(0, 0, W, H), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

            BitmapData bmpDataH = h.LockBits(new Rectangle(0, 0, W, H), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            BitmapData bmpDataS = s.LockBits(new Rectangle(0, 0, W, H), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            BitmapData bmpDataI = i.LockBits(new Rectangle(0, 0, W, H), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            int    padding = bmpDataSrc.Stride - (W * 3);
            int    r, g, b;
            byte * psrc = (byte *)bmpDataSrc.Scan0.ToPointer();
            byte * ph   = (byte *)bmpDataH.Scan0.ToPointer();
            byte * ps   = (byte *)bmpDataS.Scan0.ToPointer();
            byte * pi   = (byte *)bmpDataI.Scan0.ToPointer();
            double v;

            for (int y = 0; y < H; y++)
            {
                for (int x = 0; x < W; x++)
                {
                    b       = *(psrc++);
                    g       = *(psrc++);
                    r       = *(psrc++);
                    v       = RgbToHsi.matiz(r, g, b);
                    *(ph++) = (byte)v;
                    *(ph++) = (byte)v;
                    *(ph++) = (byte)v;

                    v       = RgbToHsi.saturacao(r, g, b);
                    *(ps++) = (byte)v;
                    *(ps++) = (byte)v;
                    *(ps++) = (byte)v;

                    v       = RgbToHsi.intensidade(r, g, b);
                    *(pi++) = (byte)v;
                    *(pi++) = (byte)v;
                    *(pi++) = (byte)v;
                }
                psrc += padding;
                ph   += padding;
                ps   += padding;
                pi   += padding;
            }
            src.UnlockBits(bmpDataSrc);
            h.UnlockBits(bmpDataH);
            s.UnlockBits(bmpDataS);
            i.UnlockBits(bmpDataI);
        }
Example #2
0
        public unsafe static string getInfo(Bitmap img, int X, int Y)
        {
            int        W          = img.Width;
            int        H          = img.Height;
            BitmapData bmpDataImg = img.LockBits(new Rectangle(0, 0, W, H), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
            int        padding    = bmpDataImg.Stride - (W * 3);
            byte *     pos        = (byte *)bmpDataImg.Scan0.ToPointer();

            pos = getPos(pos, X, Y, W, padding);
            int b = *(pos++);
            int g = *(pos++);
            int r = *(pos++);

            img.UnlockBits(bmpDataImg);

            //RGB
            string info = "RGB[";

            info += r.ToString("D" + 3) + " , ";
            info += g.ToString("D" + 3) + " , ";
            info += b.ToString("D" + 3) + "] ";

            //CMY
            info += "CMY[";
            info += (255 - r).ToString("D" + 3) + " , ";
            info += (255 - g).ToString("D" + 3) + " , ";
            info += (255 - b).ToString("D" + 3) + "] ";

            //HSI
            info += "HSI[";
            info += (int)RgbToHsi.matiz(r, g, b) + " , ";
            info += (int)RgbToHsi.saturacao(r, g, b) + " , ";
            info += (int)RgbToHsi.intensidade(r, g, b) + "] ";

            return(info);
        }