public Bitmap RenderBarrage(string comment, BarrageStyle style)
 {
     IntPtr screenDc = ApiHelper.GetDC(IntPtr.Zero);
     Graphics measureGraphics = Graphics.FromHdc(screenDc);
     SizeF size = measureGraphics.MeasureString(comment, Font);
     int width = (int)Math.Ceiling(size.Width + HorizontalMargin * 2);
     measureGraphics.Dispose();
     ApiHelper.ReleaseDC(IntPtr.Zero, screenDc);
     RectangleF rect = new Rectangle(0, 0, width, BarrageHeight);
     switch (style)
     {
         case BarrageStyle.BorderBlur:
             {
                 Bitmap bitmap = new Bitmap(width, BarrageHeight, PixelFormat.Format32bppPArgb);
                 Graphics g = Graphics.FromImage(bitmap);
                 g.SmoothingMode = SmoothingMode.AntiAlias;
                 GraphicsPath path = new GraphicsPath();
                 path.AddString(comment, Font.FontFamily, (int)Font.Style, Font.Size, rect, stringFormat);
                 g.FillPath(borderBrush, path);
                 g.DrawPath(borderPen, path);
                 g.Dispose();
                 Bitmap newBitmap = RenderUtils.BoxBlur(bitmap, BlurRadius);
                 bitmap.Dispose();
                 g = Graphics.FromImage(newBitmap);
                 g.SmoothingMode = SmoothingMode.AntiAlias;
                 g.CompositingQuality = CompositingQuality.HighQuality;
                 g.FillPath(fillBrush, path);
                 g.Dispose();
                 RenderUtils.SetAlpha(newBitmap, Transparency);
                 return newBitmap;
             }
         case BarrageStyle.Border:
             {
                 Bitmap bitmap = new Bitmap(width, BarrageHeight, PixelFormat.Format32bppPArgb);
                 Graphics g = Graphics.FromImage(bitmap);
                 g.SmoothingMode = SmoothingMode.AntiAlias;
                 GraphicsPath path = new GraphicsPath();
                 path.AddString(comment, Font.FontFamily, (int)Font.Style, Font.Size, rect, stringFormat);
                 g.DrawPath(borderPen, path);
                 g.CompositingQuality = CompositingQuality.HighQuality;
                 g.FillPath(fillBrush, path);
                 g.Dispose();
                 RenderUtils.SetAlpha(bitmap, Transparency);
                 return bitmap;
             }
         case BarrageStyle.Shadow:
             {
                 Bitmap bitmap = new Bitmap(width, BarrageHeight, PixelFormat.Format32bppPArgb);
                 Graphics g = Graphics.FromImage(bitmap);
                 g.SmoothingMode = SmoothingMode.AntiAlias;
                 RectangleF newRect = rect;
                 newRect.Offset(ShadowX, ShadowY);
                 GraphicsPath path = new GraphicsPath();
                 path.AddString(comment, Font.FontFamily, (int)Font.Style, Font.Size, newRect, stringFormat);
                 g.FillPath(borderBrush, path);
                 g.Dispose();
                 Bitmap newBitmap = RenderUtils.BoxBlur(bitmap, BlurRadius);
                 bitmap.Dispose();
                 g = Graphics.FromImage(newBitmap);
                 g.SmoothingMode = SmoothingMode.AntiAlias;
                 g.CompositingQuality = CompositingQuality.HighQuality;
                 path = new GraphicsPath();
                 path.AddString(comment, Font.FontFamily, (int)Font.Style, Font.Size, rect, stringFormat);
                 g.FillPath(fillBrush, path);
                 g.Dispose();
                 RenderUtils.SetAlpha(newBitmap, Transparency);
                 return newBitmap;
             }
         default:
             throw new ArgumentException("style参数无效。", "style");
     }
 }
        public BarrageManager(BarrageWindow parent, Size size, Configurations styleConf, Configurations actionConf)
        {
            renderer = new BarrageRenderer(styleConf);

            GlobalKeyHook.Instance.SetProcessor(
                styleConf.GetKeys("ReverseColor-Key", Keys.Control | Keys.Alt | Keys.W),
                k =>
                {
                    reverseColor = !reverseColor;
                    renderer.BorderColor = Color.FromArgb(
                        255 - renderer.BorderColor.R,
                        255 - renderer.BorderColor.G,
                        255 - renderer.BorderColor.B);
                    renderer.FillColor = Color.FromArgb(
                        255 - renderer.FillColor.R,
                        255 - renderer.FillColor.G,
                        255 - renderer.FillColor.B);

                    parent.ShowNotice(reverseColor ? "颜色:反色" : "颜色:正常");
                    return true;
                }
            );

            GlobalKeyHook.Instance.SetProcessor(
                styleConf.GetKeys("IncreaseAlpha-Key", Keys.Control | Keys.Alt | Keys.Oemplus),
                k =>
                {
                    float value = (float)Math.Round(renderer.Transparency + 0.1f, 1);
                    if (value > 1.0f)
                        value = 1.0f;
                    renderer.Transparency = value;
                    parent.ShowNotice("透明度:" + (renderer.Transparency * 100).ToString() + "%");
                    return true;
                }
            );

            GlobalKeyHook.Instance.SetProcessor(
                styleConf.GetKeys("DecreaseAlpha-Key", Keys.Control | Keys.Alt | Keys.OemMinus),
                k =>
                {
                    float value = (float)Math.Round(renderer.Transparency - 0.1f, 1);
                    if (value < 0.0f)
                        value = 0.0f;
                    renderer.Transparency = value;
                    parent.ShowNotice("透明度:" + (renderer.Transparency * 100).ToString() + "%");
                    return true;
                }
            );

            string style = styleConf.GetString("Style", "border-blur");
            switch (style)
            {
                case "border-blur":
                    this.barrageStyle = BarrageStyle.BorderBlur;
                    break;
                case "border":
                    this.barrageStyle = BarrageStyle.Border;
                    break;
                default:
                    this.barrageStyle = BarrageStyle.Shadow;
                    break;
            }
            this.barrageHeight = styleConf.GetInt("Height", 40);
            this.speed = actionConf.GetInt("Speed", 5);
            this.maxTime = actionConf.GetInt("Max-Time", 560);
            this.maxWait = actionConf.GetInt("Max-Wait", 100);
            this.maxRenderWait = actionConf.GetInt("Max-RenderWait", 500);
            this.maxCount = actionConf.GetInt("Max-Count", 200);
            this.maxLength = actionConf.GetInt("Max-Length", 40);

            this.size = size;
            barrageLines = new BarrageLine[size.Height / barrageHeight];
            for (int i = 0; i < barrageLines.Length; i++)
                barrageLines[i] = new BarrageLine(this);

            Visible = true;
        }