Esempio n. 1
0
        public static Bmp getBmpDigits()
        {
            if (_bmpDigits == null)
            {
                _bmpDigits = Bmp.create(readImageFile(Gnd.i.digitsImageFile));
            }

            return(_bmpDigits);
        }
        private Bitmap Make字幕(string line)
        {
            Bmp.Dot dotBack = new Bmp.Dot(0, 0, 0, 0);
            Bmp.Dot dotExte = new Bmp.Dot(255, 0, 0, 0);
            Bmp.Dot dotInte = new Bmp.Dot(255, 255, 255, 255);

            Bmp bmp;

            using (Bitmap b = new Bitmap(10000, 400))
            {
                using (Graphics g = Graphics.FromImage(b))
                {
                    g.FillRectangle(Brushes.Black, 0f, 0f, (float)b.Width, (float)b.Height);
                    g.DrawString(line, new Font("メイリオ", 200f, FontStyle.Regular), Brushes.White, 50f, 50f);
                }
                bmp = Bmp.create(b);
            }

            bmp.select(dot => dot.r < 128 ? dotBack : dotInte);

            {
                Rect rect = bmp.getRect(dot => dot.IsSame(dotInte));

                Gnd.i.logger.writeLine("rect.l: " + rect.l);
                Gnd.i.logger.writeLine("rect.t: " + rect.t);
                Gnd.i.logger.writeLine("rect.r: " + rect.r);
                Gnd.i.logger.writeLine("rect.b: " + rect.b);

                bmp = bmp.getRectBmp(
                    IntTools.toInt(rect.l),
                    IntTools.toInt(rect.t),
                    IntTools.toInt(rect.w),
                    IntTools.toInt(rect.h)
                    );
            }

            Bmp bmpExte;

            bmpExte = bmp.copy();
            bmpExte.select(dot => dot.IsSame(dotInte) ? dotExte : dotBack);

            using (Bitmap b = new Bitmap(bmp.table.w + 60, bmp.table.h + 60))
            {
                using (Graphics g = Graphics.FromImage(b))
                {
                    g.Clear(Color.Transparent);

                    {
                        Bitmap be = bmpExte.getBitmap();

                        for (int c = 0; c < 40; c++)
                        {
                            g.DrawImage(be, 10 + c, 10);
                            g.DrawImage(be, 10 + c, 49);
                            g.DrawImage(be, 10, 10 + c);
                            g.DrawImage(be, 49, 10 + c);
                        }
                    }

                    g.DrawImage(bmp.getBitmap(), 30, 30);
                }
                bmp = Bmp.create(b);
            }

            {
                Rect rect = bmp.getRect(dot => dot.IsSame(dotBack) == false);

                bmp = bmp.getRectBmp(
                    IntTools.toInt(rect.l),
                    IntTools.toInt(rect.t),
                    IntTools.toInt(rect.w),
                    IntTools.toInt(rect.h)
                    );
            }

            bmp = bmp.addMargin(10, 10, 10, 10, dotBack);
            bmp = bmp.expand(
                IntTools.toInt(bmp.table.w / 3.0),
                IntTools.toInt(bmp.table.h / 3.0)
                );

            {
                Rect rect = bmp.getRect(dot => dot.IsSame(dotBack) == false);

                bmp = bmp.getRectBmp(
                    IntTools.toInt(rect.l),
                    IntTools.toInt(rect.t),
                    IntTools.toInt(rect.w),
                    IntTools.toInt(rect.h)
                    );
            }

            {
                int w;
                int h;

                h = IntTools.toInt(Img_H * 0.08);
                w = IntTools.toInt(h * bmp.table.w * 1.0 / bmp.table.h);

                w = Math.Min(w, Img_W);

                bmp = bmp.expand(w, h);
            }

            return(bmp.getBitmap());
        }