public static Bitmap DrawText(this Bitmap Image, string TextToDraw, Font FontToUse, Brush BrushUsing, RectangleF BoxToDrawWithin, string FileName = "") { Image.ThrowIfNull("Image"); FontToUse.ThrowIfNull("FontToUse"); BrushUsing.ThrowIfNull("BrushUsing"); BoxToDrawWithin.ThrowIfNull("BoxToDrawWithin"); ImageFormat FormatUsing = FileName.GetImageFormat(); Bitmap NewBitmap = new Bitmap(Image, Image.Width, Image.Height); using (Graphics TempGraphics = Graphics.FromImage(NewBitmap)) { TempGraphics.DrawString(TextToDraw, FontToUse, BrushUsing, BoxToDrawWithin); } if (!string.IsNullOrEmpty(FileName)) NewBitmap.Save(FileName, FormatUsing); return NewBitmap; }
/// <summary> /// Gets the specified font. /// </summary> /// <param name="prototype">The font's prototype this font will be based on</param> /// <param name="style">The overriden style.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">prototype</exception> public static Font GetFont(Font prototype, FontStyle style = FontStyle.Regular) { prototype.ThrowIfNull(nameof(prototype)); return GetFont(prototype.FontFamily.Name, prototype.Size, style, prototype.Unit); }