/// <summary> /// Used to create "round buttons" for menus. /// Altering this method will affect visual stying across several projects. /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="foreCol"></param> /// <param name="backCol"></param> /// <param name="message"></param> /// <param name="font"></param> /// <returns></returns> 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()); }
/// <summary> /// Used to create a stand-in image with a message on it. /// /// eg: GenerateDebugImage(1024,1024, "File not found: " + imageName); /// </summary> /// <returns></returns> public static Bitmap GenerateDebugImage(int width, int height, string message) { Bitmap bmp = new Bitmap(width, height); GDIPlusRenderer r = new GDIPlusRenderer(bmp); r.Clear(Color.Fuchsia); 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); }