コード例 #1
0
        public static Bitmap RenderAsGDIBitmap(this IPixelBufferRenderable item)
        {
            Bitmap    b = new Bitmap(item.PreferedSizeInPixels.Width, item.PreferedSizeInPixels.Height);
            IRenderer r = new GDIPlusRenderer(b);

            item.Render(r, new Rectangle(0, 0, r.Width, r.Height));
            r.Close();

            return(b);
        }
コード例 #2
0
ファイル: BitmapHelpers.cs プロジェクト: busyDuckman/WDLib
        public static Bitmap GenerateMessageInCircle(int width, int height, Color foreCol, Color backCol, string message, Font font = null)
        {
            GDIPlusRenderer r = new GDIPlusRenderer(width, height);

            r.SetHighQuality(true);
            //circle
            int lineWidth = Range.clamp(Math.Min(width, height) / 128, 1, 10);
            int diamater  = Math.Max(Math.Min(width, height) - lineWidth - 1, 1);
            int cX        = width / 2;
            int cY        = height / 2;

            r.FillCircle(backCol, cX, cY, diamater / 2);
            r.DrawCircle(foreCol, lineWidth, cX, cY, diamater / 2);

            //text
            if (!String.IsNullOrWhiteSpace(message))
            {
                StringFormat stringFormat = new StringFormat();
                stringFormat.Alignment     = StringAlignment.Center;
                stringFormat.LineAlignment = StringAlignment.Center;

                Font _font = font;

                if (_font == null)
                {
                    float fontSize = Math.Min(width, height) / 10.0f;
                    fontSize = Range.clamp(fontSize, 10, 45);
                    _font    = new Font("Arial", fontSize, FontStyle.Bold);
                }

                try
                {
                    r.DrawStringAligned(foreCol, message, _font, cX, cY, HorizontalAlignment.Centre, VerticalAlignment.Centre);
                }
                finally
                {
                    if (font == null)
                    {
                        //_font was created in this method, not supplied via font
                        _font.TryDispose();
                    }
                }
            }

            return(r.RenderTargetAsGDIBitmap());
        }
コード例 #3
0
ファイル: BitmapHelpers.cs プロジェクト: busyDuckman/WDLib
        public static Bitmap GenerateDebugImage(int width, int height, string message)
        {
            GradientPattern pattern = new GradientPattern();

            pattern.bottomLeft  = (Color)QColor.generateRandomOpaque(128, 255);
            pattern.bottomRight = (Color)QColor.generateRandomOpaque(128, 255);
            pattern.topLeft     = Color.Fuchsia;
            pattern.topRight    = Color.Fuchsia;

            Bitmap          bmp      = pattern.makeBitmap(width, height);
            GDIPlusRenderer r        = new GDIPlusRenderer(bmp);
            float           fontSize = Math.Min(width, height) / 10.0f;

            fontSize = Range.clamp(fontSize, 10, 45);
            using (Font f = new Font("Arial", fontSize, FontStyle.Bold))
            {
                TextFormat tf = new TextFormat(f, Color.Black, true, Color.White, false);
                tf.render(r, message, 0, height / 2);
                bmp = r.RenderTargetAsGDIBitmap();
            }


            return(bmp);
        }