Ejemplo n.º 1
0
        public static bool AlphaSpots(ref Bitmap bmp, byte offset,
                                                               params RadiusPos[] rp)
        {
            if (bmp.PixelFormat != PixelFormat.Format24bppRgb)
                return false;

            if (rp.Length == 0) return false;

            int w = bmp.Width;
            int h = bmp.Height;

            Bitmap tmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);
            Graphics g = Graphics.FromImage(tmp);
            g.DrawImageUnscaled(bmp, 0, 0);
            g.Dispose();

            double cx, cy, rr, r, f;

            BmpProc32 src = new BmpProc32(tmp);

            for (int y = 0; y < h; y++)
                for (int x = 0; x < w; x++)
                    src[x, y, eRGB.a] = offset;

            for (int i = 0; i < rp.Length; i++)
            {
                cx = rp[i].PosX; cy = rp[i].PosY;
                rr = rp[i].Radius; rr = rr * rr;

                for (int y = 0; y < h; y++)
                    for (int x = 0; x < w; x++)
                    {
                        r = (x - cx) * (x - cx) + (y - cy) * (y - cy);
                        f = 1.2d * (1d - r / rr);
                        if (f > 1d) f = 1d;
                        if (f > 0)
                            src[x, y, eRGB.a] = Math.Max(src[x, y, eRGB.a], AdjustByte(255 * f));
                    }
            }

            src.Dispose();

            bmp.Dispose();

            bmp = tmp;

            return true;
        }
Ejemplo n.º 2
0
        public static bool AlphaRects(ref Bitmap bmp, byte offset,
                                                       params Rectangle[] rct)
        {
            if (bmp.PixelFormat != PixelFormat.Format24bppRgb)
                return false;

            if (rct.Length == 0) return false;

            int w = bmp.Width;
            int h = bmp.Height;

            Bitmap tmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);
            Graphics g = Graphics.FromImage(tmp);
            g.DrawImageUnscaled(bmp, 0, 0);
            g.Dispose();

            double pi = Math.PI;
            double f;

            BmpProc32 src = new BmpProc32(tmp);

            for (int y = 0; y < h; y++)
                for (int x = 0; x < w; x++)
                    src[x, y, eRGB.a] = offset;

            for (int i = 0; i < rct.Length; i++)
            {

                for (int y = rct[i].Y; y < rct[i].Y + rct[i].Height; y++)
                    for (int x = rct[i].X; x < rct[i].X + rct[i].Width; x++)
                    {
                        if ((x < 0) | (x > w - 1) |
                                       (y < 0) | (y > h - 1)) continue;

                        f = 1.2 * Math.Sin((x - rct[i].X) * pi / rct[i].Width) *
                                       Math.Sin((y - rct[i].Y) * pi / rct[i].Height);
                        if (f > 1d) f = 1d;
                        src[x, y, eRGB.a] = Math.Max(src[x, y, eRGB.a], (byte)(f * 255));
                    }

            }

            src.Dispose();

            bmp.Dispose();

            bmp = tmp;

            return true;
        }
Ejemplo n.º 3
0
        public static bool SetAlpha(ref Bitmap bmp, int percent)
        {
            int w = bmp.Width;
            int h = bmp.Height;

            Bitmap tmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);
            Graphics g = Graphics.FromImage(tmp);
            g.DrawImageUnscaled(bmp, 0, 0);
            g.Dispose();

            byte alpha = (byte)(255 * percent / 100);

            BmpProc32 dst = new BmpProc32(tmp);

            for (int y = 0; y < h; y++)
                for (int x = 0; x < w; x++)
                    dst[x, y, eRGB.a] = alpha;

            dst.Dispose();
            bmp.Dispose();

            bmp = tmp;

            return true;
        }
Ejemplo n.º 4
0
        public static bool SetFramedAlpha(ref Bitmap bmp)
        {
            if (bmp.PixelFormat != PixelFormat.Format24bppRgb) return false;

            int w = bmp.Width;
            int h = bmp.Height;

            Bitmap tmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);

            Graphics g = Graphics.FromImage(tmp);
            g.DrawImageUnscaled(bmp, 0, 0);
            g.Dispose();

            double pi = Math.PI;
            double f;

            BmpProc32 dst = new BmpProc32(tmp);

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    f = Math.Sin(y * pi / h) * Math.Sin(x * pi / w);
                    dst[x, y, eRGB.a] = (byte)(255 * f);
                }
            }

            dst.Dispose();

            bmp.Dispose();
            bmp = tmp;

            return true;
        }
Ejemplo n.º 5
0
        public static bool Diacross(ref Bitmap bmp, bool bFine,
                                            Color penColor, Color bkColor)
        {
            if (bmp.PixelFormat != PixelFormat.Format24bppRgb)
                return false;

            int w = bmp.Width;
            int h = bmp.Height;

            Graphics g;

            GrayScale(ref bmp);
            HistoStretch(ref bmp);

            Bitmap[] pattern = new Bitmap[4];
            TextureBrush[] tb = new TextureBrush[4];

            if (bFine)
            {
                Pen pn = new Pen(penColor, 1.8f);
                pn.Alignment = PenAlignment.Center;

                PointF[] start = { new PointF(0f, 0.5f), new PointF(0.5f, 0F),
                                            new PointF(0f, 2.5f), new PointF(2.5f, 0f) };
                PointF[] stop = { new PointF(4f, 0.5f), new PointF(0.5f, 4f),
                                            new PointF(4f, 2.5f), new PointF(2.5f, 4f) };

                float[] angle = { -37f, -53f };

                for (int i = 0; i < 4; i++)
                {
                    pattern[i] = new Bitmap(4, 4, PixelFormat.Format24bppRgb);
                    g = Graphics.FromImage(pattern[i]);
                    g.Clear(Color.White);
                    g.DrawLine(pn, start[i], stop[i]);
                    g.Dispose();

                    tb[i] = MakePatternBrush(pattern[i], angle[i % 2]);
                }

                pn.Dispose();
            }
            else
            {
                Pen pn = new Pen(penColor, 2.2f);
                pn.Alignment = PenAlignment.Center;

                Point[] start = { new Point(0, 1), new Point(1, 0),
                                        new Point(0, 4), new Point(4, 0) };
                Point[] stop = { new Point(9, 1), new Point(1, 9),
                                        new Point(9, 4), new Point(4, 9) };

                float[] angle = { -30f, -60f };

                for (int i = 0; i < 4; i++)
                {
                    pattern[i] = new Bitmap(6, 6, PixelFormat.Format32bppArgb);
                    g = Graphics.FromImage(pattern[i]);
                    g.Clear(Color.White);
                    g.DrawLine(pn, start[i], stop[i]);
                    g.Dispose();

                    tb[i] = MakePatternBrush(pattern[i], angle[i % 2]);
                }

                pn.Dispose();
            }

            Bitmap dst = new Bitmap(w, h, PixelFormat.Format24bppRgb);
            Graphics gdst = Graphics.FromImage(dst);
            gdst.Clear(bkColor);

            byte[] th = { 255, 191, 128, 64 };

            Bitmap tgt;

            BmpProc8 mod = new BmpProc8(bmp);

            for (int i = 0; i < 4; i++)
            {

                tgt = new Bitmap(w, h, PixelFormat.Format32bppArgb);

                g = Graphics.FromImage(tgt);
                g.FillRectangle(tb[i], 0, 0, w, h);
                g.Dispose();
                tb[i].Dispose();
                pattern[i].Dispose();

                BmpProc32 src = new BmpProc32(tgt);

                for (int y = 0; y < h; y++)
                    for (int x = 0; x < w; x++)
                    {
                        if (mod[x, y] < th[i])
                            src[x, y, eRGB.a] =
                                AdjustByte((double)(255 - src[x, y, eRGB.r]) *
                                    ((1d - ((double)mod[x, y] / (double)th[i]))));
                        else
                            src[x, y, eRGB.a] = 0;
                    }

                src.Dispose();

                gdst.DrawImageUnscaled(tgt, 0, 0);

                tgt.Dispose();
            }

            mod.Dispose();
            bmp.Dispose();
            gdst.Dispose();

            bmp = dst;
            return true;
        }