Exemple #1
0
 public Color GetPixel(Int32 x, Int32 y)
 {
     return(m_bmpImage.GetPixel(x, y));
 }
Exemple #2
0
        public void Blur(Int32 nHorz, Int32 nVert)
        {
            Single nWeightSum;

            Single[] nWeights;

            FastBitmap bmpBlur = (FastBitmap)m_bmpImage.Clone();

            m_bmpImage.Lock();
            bmpBlur.Lock();

            // horizontal blur

            nWeights = new Single[nHorz * 2 + 1];
            for (Int32 i = 0; i < nHorz * 2 + 1; i++)
            {
                Single y = Gauss(-nHorz + i, 0, nHorz);
                nWeights[i] = y;
            }

            for (Int32 row = 0; row < m_bmpImage.Height; row++)
            {
                for (Int32 col = 0; col < m_bmpImage.Width; col++)
                {
                    Double r = 0;
                    Double g = 0;
                    Double b = 0;
                    nWeightSum = 0;
                    for (Int32 i = 0; i < nHorz * 2 + 1; i++)
                    {
                        Int32 x = col - nHorz + i;
                        if (x < 0)
                        {
                            i += -x;
                            x  = 0;
                        }
                        if (x > m_bmpImage.Width - 1)
                        {
                            break;
                        }
                        Color c = m_bmpImage.GetPixel(x, row);
                        r          += c.R * nWeights[i];
                        g          += c.G * nWeights[i];
                        b          += c.B * nWeights[i];
                        nWeightSum += nWeights[i];
                    }
                    r /= nWeightSum;
                    g /= nWeightSum;
                    b /= nWeightSum;
                    Byte br = (Byte)Math.Round(r);
                    Byte bg = (Byte)Math.Round(g);
                    Byte bb = (Byte)Math.Round(b);
                    if (br > 255)
                    {
                        br = 255;
                    }
                    if (bg > 255)
                    {
                        bg = 255;
                    }
                    if (bb > 255)
                    {
                        bb = 255;
                    }
                    bmpBlur.SetPixel(col, row, Color.FromArgb(br, bg, bb));
                }
            }

            // vertical blur

            nWeights = new Single[nVert * 2 + 1];
            for (Int32 i = 0; i < nVert * 2 + 1; i++)
            {
                Single y = Gauss(-nVert + i, 0, nVert);
                nWeights[i] = y;
            }

            for (Int32 col = 0; col < m_bmpImage.Width; col++)
            {
                for (Int32 row = 0; row < m_bmpImage.Height; row++)
                {
                    Double r = 0;
                    Double g = 0;
                    Double b = 0;
                    nWeightSum = 0;
                    for (Int32 i = 0; i < nVert * 2 + 1; i++)
                    {
                        Int32 y = row - nVert + i;
                        if (y < 0)
                        {
                            i += -y;
                            y  = 0;
                        }
                        if (y > m_bmpImage.Height - 1)
                        {
                            break;
                        }
                        Color c = bmpBlur.GetPixel(col, y);
                        r          += c.R * nWeights[i];
                        g          += c.G * nWeights[i];
                        b          += c.B * nWeights[i];
                        nWeightSum += nWeights[i];
                    }
                    r /= nWeightSum;
                    g /= nWeightSum;
                    b /= nWeightSum;
                    Byte br = (Byte)Math.Round(r);
                    Byte bg = (Byte)Math.Round(g);
                    Byte bb = (Byte)Math.Round(b);
                    if (br > 255)
                    {
                        br = 255;
                    }
                    if (bg > 255)
                    {
                        bg = 255;
                    }
                    if (bb > 255)
                    {
                        bb = 255;
                    }
                    m_bmpImage.SetPixel(col, row, Color.FromArgb(br, bg, bb));
                }
            }

            bmpBlur.Dispose();          // will unlock
            m_bmpImage.Unlock();
        }