本文整理汇总了C#中Android.Graphics.Paint.SetTypeface方法的典型用法代码示例。如果您正苦于以下问题:C# Paint.SetTypeface方法的具体用法?C# Paint.SetTypeface怎么用?C# Paint.SetTypeface使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Graphics.Paint
的用法示例。
在下文中一共展示了Paint.SetTypeface方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBackground
public override ImageReference GetBackground (int row, int col)
{
var pt = new Point (row, col);
ImageReference imgRef = null;
if(mBackgrounds.ContainsKey(pt))
imgRef = mBackgrounds [pt];
if (imgRef == null) {
var bm = Bitmap.CreateBitmap (200, 200, Bitmap.Config.Argb8888);
var c = new Canvas (bm);
var p = new Paint ();
c.DrawRect (0, 0, 200, 200, p);
p.AntiAlias = true;
p.SetTypeface (Typeface.Default);
p.TextSize = 64;
p.Color = Color.LightGray;
c.DrawText (col + "-" + row, 20, 100, p);
imgRef = ImageReference.ForBitmap (bm);
mBackgrounds.Add (pt, imgRef);
}
return imgRef;
}
示例2: CreateBitmapData
void CreateBitmapData (string str, out byte[] bitmapData, out int width, out int height)
{
Paint paint = new Paint ();
paint.TextSize = 128;
paint.TextAlign = Paint.Align.Left;
paint.SetTypeface (Typeface.Default);
width = height = 256;
float textWidth = paint.MeasureText (str);
using (Bitmap bitmap = Bitmap.CreateBitmap (width, height, Bitmap.Config.Argb8888)) {
Canvas canvas = new Canvas (bitmap);
paint.Color = str != " " ? Color.White : Color.LightGray;
canvas.DrawRect (new Rect (0, 0, width, height), paint);
paint.Color = Color.Black;
canvas.DrawText (str, (256 - textWidth) / 2f, (256 - paint.Descent () - paint.Ascent ()) / 2f, paint);
bitmapData = new byte [width * height * 4];
Java.Nio.ByteBuffer buffer = Java.Nio.ByteBuffer.Allocate (bitmapData.Length);
bitmap.CopyPixelsToBuffer (buffer);
buffer.Rewind ();
buffer.Get (bitmapData, 0, bitmapData.Length);
}
}
示例3: Initialize
void Initialize ()
{
_basePaint = new Paint ();
_basePaint.Color = Color.Black;
_basePaint.AntiAlias = true;
_basePaint.SetStyle (Paint.Style.Fill);
_gridPaint = new Paint ();
_gridPaint.SetStyle (Paint.Style.Stroke);
_gridPaint.Color = Color.ParseColor (RSColors.RS_LIGHT_GRAY);
_circlesPaint = new Paint ();
_circlesPaint.Color = Color.ParseColor (RSColors.PURPLE_4);
_circlesPaint.SetStyle (Paint.Style.Fill);
_circlesPaint.AntiAlias = true;
_dataLabelPaint = new Paint ();
_dataLabelPaint.Color = Color.ParseColor (RSColors.GREEN_4);
_dataLabelPaint.TextSize = PixelUtil.GetPixelFromDP (dataLabelSize, _context.Resources);
_dataLabelPaint.SetStyle (Paint.Style.Stroke);
_dataLabelPaint.AntiAlias = true;
_dataLabelPaint.SetTypeface (Typeface.DefaultBold);
_dataLabelPaint.TextAlign = Paint.Align.Center;
_dataLabelBgPaint = new Paint ();
_dataLabelBgPaint.Color = Color.White;
_dataLabelBgPaint.SetStyle (Paint.Style.Fill);
_xLabelPaint = new Paint ();
_xLabelPaint.Color = Color.Black;
_xLabelPaint.SetStyle (Paint.Style.Stroke);
_xLabelPaint.AntiAlias = true;
_xLabelPaint.TextAlign = Paint.Align.Center;
_xLabelPaint.TextSize = PixelUtil.GetPixelFromDP (xLabelSize, _context.Resources);
}
示例4: GetBackgroundForPage
public override Android.Graphics.Drawables.Drawable GetBackgroundForPage (int row, int column)
{
Point pt = new Point (column, row);
Drawable drawable;
if (!mBackgrounds.ContainsKey(pt))
{
// the key wasn't found in Dictionary
var bm = Bitmap.CreateBitmap(200, 200, Bitmap.Config.Argb8888);
var c = new Canvas(bm);
var p = new Paint();
// Clear previous image.
c.DrawRect(0, 0, 200, 200, p);
p.AntiAlias = true;
p.SetTypeface(Typeface.Default);
p.TextSize = 64;
p.Color = Color.LightGray;
p.TextAlign = Paint.Align.Center;
c.DrawText(column + "-" + row, 100, 100, p);
drawable = new BitmapDrawable(owner.Resources, bm);
mBackgrounds.Add(pt, drawable);
}
else
{
// the key was found
drawable = mBackgrounds[pt];
}
return drawable;
}
示例5: DrawingImageView
public DrawingImageView(Context context, Fragment fragment): base(context) {
mPaint = new Paint();
mPaint.AntiAlias = true;
mPaint.Dither = true;
mPaint.Color = Color.Yellow;
mPaint.SetStyle (Paint.Style.Stroke);
mPaint.StrokeJoin = Paint.Join.Round;
mPaint.StrokeCap = Paint.Cap.Round;
mPaint.StrokeWidth = 10;
cPaint = new Paint ();
cPaint.Color = Color.Yellow;
cPaint.StrokeJoin = Paint.Join.Round;
cPaint.StrokeCap = Paint.Cap.Round;
cPaint.SetTypeface(Typeface.Default);
cPaint.TextSize = 40;
mPath = new Android.Graphics.Path();
mBitmapPaint = new Paint();
mBitmapPaint.Color = Color.Yellow;
DrawingStatus = DrawingType.None;
_fragment = fragment;
}
示例6: ApplyCustomTypeFace
private static void ApplyCustomTypeFace(Paint paint, Typeface tf, Android.Graphics.Color color)
{
int oldStyle;
Typeface old = paint.Typeface;
if (old == null)
{
oldStyle = 0;
}
else
{
oldStyle = (int)old.Style;
}
int fake = oldStyle & ~(int)tf.Style;
if ((fake & (int)TypefaceStyle.Bold) != 0)
{
paint.FakeBoldText = true;
}
if ((fake & (int)TypefaceStyle.Italic) != 0)
{
paint.TextSkewX = -0.25f;
}
paint.SetARGB(color.A, color.R, color.G, color.B);
paint.SetTypeface(tf);
}
示例7: InitStepCountPaint
void InitStepCountPaint()
{
stepcountPaint = new Paint();
//stepcountPaint.Color = Color.White;
stepcountPaint.SetARGB(255, 50, 151, 218);
stepcountPaint.SetTypeface(Typeface.Create(Typeface.SansSerif, TypefaceStyle.Normal));
stepcountPaint.AntiAlias = true;
stepcountPaint.TextSize = owner.Resources.GetDimension(Resource.Dimension.StepCountTextSize);
}
示例8: ApplyCustomTypeface
private static void ApplyCustomTypeface(Paint paint, Typeface tf, TypefaceStyle style, int size)
{
if (style == TypefaceStyle.Italic)
paint.TextSkewX = -0.25f;
if(size > 0)
paint.TextSize = size;
paint.SetTypeface (tf);
}
示例9: ApplyCustomTypeFace
private void ApplyCustomTypeFace(Paint paint, Typeface tf)
{
paint.FakeBoldText = false;
paint.TextSkewX = 0f;
paint.SetTypeface(tf);
if (_rotate)
paint.ClearShadowLayer();
if (_iconSizeRatio > 0)
paint.TextSize = (paint.TextSize * _iconSizeRatio);
else if (_iconSizePx > 0)
paint.TextSize = _iconSizePx;
if (_iconColor < Int32.MaxValue)
paint.Color = new Color(_iconColor);
paint.Flags = paint.Flags | PaintFlags.SubpixelText;
}
示例10: Draw
/// <Docs>The Canvas to which the View is rendered.</Docs>
/// <summary>
/// Draw the specified canvas.
/// </summary>
/// <param name="canvas">Canvas.</param>
public override void Draw(Android.Graphics.Canvas canvas)
{
base.Draw(canvas);
var paintForAngle = new Paint { Color = (Android.Graphics.Color.White), TextSize = 37f };
paintForAngle.SetStyle(Paint.Style.Stroke);
paintForAngle.SetTypeface(Typeface.CreateFromAsset(Forms.Context.Assets, "Fonts/fontawesome.ttf"));
canvas.DrawText('\uf078'.ToString(), (float)(canvas.ClipBounds.CenterX() * 1.65), (float)(canvas.ClipBounds.CenterY() * 1.15), paintForAngle);
#region Disposing
paintForAngle.Dispose();
canvas.Dispose();
#endregion
}
示例11: apply
private static void apply(Paint paint, Typeface tf) {
TypefaceStyle oldStyle;
var old = paint.Typeface;
if (old == null) {
oldStyle = 0;
} else {
oldStyle = old.Style;
}
var fake = oldStyle & ~tf.Style;
if ((fake & TypefaceStyle.Bold) == TypefaceStyle.Bold) {
paint.FakeBoldText = true;
}
if ((fake & TypefaceStyle.Italic) == TypefaceStyle.Italic) {
paint.TextSkewX = -0.25f;
}
paint.SetTypeface(tf);
paint.Flags = paint.Flags | PaintFlags.SubpixelText;
}
示例12: AdjustTextToSize
public static float AdjustTextToSize(string text, SizeF box, float edgeInset, Context context)
{
SizeF constrainSize = new SizeF (box.Width - edgeInset, 9999);
float toReturn = 0f;
Paint paint = new Paint (PaintFlags.AntiAlias);
paint.TextSize = 16f;
paint.SetTypeface (Typeface.Default);
float height = ImageHelper.convertDpToPixel (paint.MeasureText (text), context);
if (height > box.Height - edgeInset) {
do {
height -= 0.5f;
paint.TextSize = height;
height = ImageHelper.convertDpToPixel (paint.MeasureText (text), context);
} while (height > box.Height - edgeInset);
toReturn = paint.TextSize;
} else if (height < box.Height - edgeInset) {
do {
height += 0.5f;
paint.TextSize = height;
height = ImageHelper.convertDpToPixel (paint.MeasureText (text), context);
} while (height < box.Height - edgeInset);
toReturn = paint.TextSize;
} else {
toReturn = paint.TextSize;
}//end if else
return toReturn;
}
示例13: CreateTextPaint
private Paint CreateTextPaint(Color defaultInteractiveColor, Typeface typeface)
{
Paint paint = new Paint ();
paint.Color = defaultInteractiveColor;
paint.SetTypeface (typeface);
paint.AntiAlias = true;
return paint;
}
示例14: GetTextParamsForCallout
/// <summary>
/// Creates and returns the text parameters for the given callout text area.
/// </summary>
/// <returns>
/// A Pair<UIFont, SizeF> containing the font and text size.
/// </returns>
/// <param name='textRect'>
/// The current text area of the callout.
/// </param>
/// <param name='text'>
/// The text for which to calculate and create the parameters.
/// </param>
public static float GetTextParamsForCallout(RectangleF textRect, string text, Context context)
{
SizeF constrainSize = new SizeF (textRect.Width, 9999);
Paint paint = new Paint (PaintFlags.AntiAlias);
paint.TextSize = 18f;
paint.SetTypeface (Typeface.Default);
float height = ImageHelper.convertDpToPixel (paint.MeasureText (text), context);
float minHeight = textRect.Height - 2f;
if (height > minHeight) {
do {
height -= 1f;
paint.TextSize = height;
height = ImageHelper.convertDpToPixel (paint.MeasureText (text), context);
} while (height > textRect.Height);
} else if (height < minHeight) {
do {
height += 1f;
paint.TextSize = height;
height = ImageHelper.convertDpToPixel (paint.MeasureText (text), context);
} while (height < minHeight);
}//end if else
return paint.TextSize;
}
示例15: ApplyFontToPaint
static void ApplyFontToPaint(Font f, Paint p)
{
var fi = GetFontInfo (f);
p.SetTypeface (fi.Typeface);
p.TextSize = f.Size;
if (fi.FontMetrics == null) {
fi.FontMetrics = new AndroidFontMetrics (p);
}
}