public TextBlock SetText(TextEventArgs textEventArgs) { using (var graphics = Graphics.FromImage(bitmap)) { var stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; stringFormat.FormatFlags = StringFormatFlags.NoWrap; graphics.TextRenderingHint = TextRenderingHint.AntiAlias; SizeF fontSizeTemplate = new SizeF(bitmap.Size); fontSizeTemplate.Width = fontSizeTemplate.Width - fontSizeTemplate.Height; //make room for useragent bitmap if (textEventArgs.isGeo) { fontSizeTemplate.Width = fontSizeTemplate.Width - fontSizeTemplate.Height; //make room for geo bitmap } var fontSize = TextUtils.GetFontSize(graphics, textEventArgs.Text, font, fontSizeTemplate); var textSize = graphics.MeasureString(textEventArgs.Text, new Font(font.FontFamily, fontSize)); using (Brush bgBrush = new SolidBrush(Color.Black)) using (Brush brush = new SolidBrush(Color.FromArgb(72, 206, 247))) { graphics.FillRectangle(bgBrush, new RectangleF(0, 0, bitmap.Size.Width, bitmap.Size.Height)); graphics.DrawString(textEventArgs.Text, new Font(font.FontFamily, fontSize), brush, new RectangleF(fontSizeTemplate.Height, 0, fontSizeTemplate.Width, fontSizeTemplate.Height), stringFormat); if (textEventArgs.isGeo) { var xPos = fontSizeTemplate.Height + (fontSizeTemplate.Width / 2) + (textSize.Width / 2); graphics.DrawImage(Resource.earth, new RectangleF(xPos, 0, fontSizeTemplate.Height, fontSizeTemplate.Height)); } Bitmap userAgentBitmap = null; switch (textEventArgs.userAgentType) { case UserAgentType.ANDROID: userAgentBitmap = Resource.android; break; case UserAgentType.IPHONE: userAgentBitmap = Resource.apple; break; case UserAgentType.CHROME: userAgentBitmap = Resource.chrome; break; case UserAgentType.FIREFOX: userAgentBitmap = Resource.firefox; break; case UserAgentType.IE: userAgentBitmap = Resource.ie; break; case UserAgentType.NETSCAPE: userAgentBitmap = Resource.netscape; break; case UserAgentType.OPERA: userAgentBitmap = Resource.opera; break; case UserAgentType.SAFARI: userAgentBitmap = Resource.safari; break; case UserAgentType.SAFARI_ANDROID: userAgentBitmap = Resource.safari_android; break; default: userAgentBitmap = Resource.netscape; break; } if (bitmap != null) { graphics.DrawImage(userAgentBitmap, new RectangleF(0, 0, fontSizeTemplate.Height, fontSizeTemplate.Height)); } } } return(this); }