Beispiel #1
0
        public void Render(BillboardTextComponent text)
        {
            var color         = new SolidColorBrush(ToMediaColor(text.TextColor));
            var formattedText = new FormattedText(text.Text, CultureInfo.InvariantCulture,
                                                  FlowDirection.LeftToRight, typeface, text.FontSize, color);

            formattedText.SetFontSize(100, 0, text.Text.Length);

            formattedText.PixelsPerDip = 50;

            var renderTargetBitmapWidth  = (int)(formattedText.Width / 2);
            var renderTargetBitmapHeight = (int)(formattedText.Height / 2);

            var visual = new DrawingVisual();

            using (DrawingContext drawingContext = visual.RenderOpen()) {
                drawingContext.DrawText(formattedText, new System.Windows.Point(0, 0));
            }
            var source = new RenderTargetBitmap(renderTargetBitmapWidth, renderTargetBitmapHeight, 50, 50, PixelFormats.Pbgra32);

            source.Clear();
            source.Render(visual);
            source.Freeze();

            var bitmap = new Bitmap(source.PixelWidth, source.PixelHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            var data   = bitmap.LockBits(new Rectangle(System.Drawing.Point.Empty, bitmap.Size), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            source.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
            bitmap.UnlockBits(data);

            RenderedBitmapText = bitmap;

            renderedTextCompTag = text.Tag;
            Scale = (float)text.FontSize / 100f;
        }
Beispiel #2
0
 public bool IsRendered(BillboardTextComponent text) => renderedTextCompTag == text.Tag;