public override void Initialize() { LoadedFont = ContentLoader.LoadContent <Font>("content/Awesome.ttf"); LoadedFont.FontSize = 48; DrawableScore = Drawables.Create <DrawableFont>(); DrawableScore.Font = LoadedFont; DrawableScore.Position = new Vec2(15, 15); DrawableScore.Color = Color.Green; Entities.Create <Space>(); Player = Entities.Create <Player>(); SpaceSpawnLogic = Logics.Create <SpaceSpawnLogic>(); }
public static string AddTextToImage(string imageFile, string text) { var image = new MagickImage(imageFile); using (var imgText = new MagickImage()) { var drawable = new DrawableText(0, 10, text); var gravity = new DrawableGravity(Gravity.North); var font = new DrawableFont("Arial"); var antialias = new DrawableTextAntialias(true); var size = new DrawableFontPointSize(50); var color = new DrawableFillColor(Color.Snow); var strokeColor = new DrawableStrokeColor(Color.OrangeRed); image.Draw(drawable, gravity, font, antialias, size, color, strokeColor); } // Save the result string outputImage = TempFolder + "\\waterMark_" + Path.GetFileName(imageFile); image.Write(outputImage); return(outputImage); }
public void Stamp(ThumbnailSheetCreateRequest request, string filePath, TimeSpan time) { var stampText = time.ToString(request.VideoDurationInSeconds >= 3600 ? @"hh\:mm\:ss" : @"mm\:ss"); var tempFilePath = filePath + ".tmp.png"; using (var imgText = new MagickImage(filePath)) { var drawable = new DrawableText(5, 5, stampText); var gravity = new DrawableGravity(Gravity.Southeast); var font = new DrawableFont("Tahoma"); var antialias = new DrawableTextAntialias(true); var size = new DrawableFontPointSize(48); var color = new DrawableFillColor(MagickColors.Black); var strokecolor = new DrawableStrokeColor(MagickColors.AliceBlue); imgText.Draw(drawable, gravity, font, antialias, size, color, strokecolor); imgText.Write(tempFilePath); } File.Delete(filePath); File.Move(tempFilePath, filePath); }
static public void DrawEnhancedText( this IMagickImage <byte> image, string text, Gravity gravity, int x, int y, MagickColor foreground, DrawableFont font, double fontPointSize, int maxWidth, bool ellipsize = true) { var settings = new MagickReadSettings() { BackgroundColor = MagickColors.Transparent, Width = maxWidth, TextGravity = gravity, TextAntiAlias = false }; //settings.SetDefine("pango:wrap", "char"); if (ellipsize) { settings.SetDefine("pango:ellipsize", "end"); } // Escape text for use in pango markup language // For some reason the text must be excaped twice otherwise it will not work text = SecurityElement.Escape(SecurityElement.Escape(text)); using var textArea = new MagickImage($@"pango:<span size=""{fontPointSize * 1000}"" font_family=""{ font.Family }"" stretch=""{font.Stretch}"" style=""{(font.Style == FontStyleType.Any ? FontStyleType.Normal : font.Style)}"" weight=""{font.Weight}"" foreground=""white"" >{text}</span>", settings); using var colored = new MagickImage(foreground, textArea.Width, textArea.Height); colored.Alpha(AlphaOption.On); colored.Composite(textArea, CompositeOperator.Multiply, Channels.Alpha); image.Composite(colored, x, y, CompositeOperator.Over); }
static public IDrawables <byte> Font(this IDrawables <byte> drawable, DrawableFont font) => drawable.Font(font.Family, font.Style, font.Weight, font.Stretch);
static public void DrawEnhancedText( this IMagickImage <byte> image, string text, int x, int y, MagickColor foreground, DrawableFont font, double fontPointSize, int maxWidth, bool ellipsize = true) => DrawEnhancedText(image, text, Gravity.Undefined, x, y, foreground, font, fontPointSize, maxWidth, ellipsize);