当前位置: 首页>>代码示例>>Java>>正文


Java Paint.getTextBounds方法代码示例

本文整理汇总了Java中android.graphics.Paint.getTextBounds方法的典型用法代码示例。如果您正苦于以下问题:Java Paint.getTextBounds方法的具体用法?Java Paint.getTextBounds怎么用?Java Paint.getTextBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.Paint的用法示例。


在下文中一共展示了Paint.getTextBounds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: calcTextBounds

import android.graphics.Paint; //导入方法依赖的package包/类
/**
 * Returns the bounding rectangle of the given _text, with the size and style defined in the _textPaint centered in the middle of the _textBounds
 *
 * @param _text       The text.
 * @param _textPaint  The paint defining the text size and style.
 * @param _textBounds The rect where the text will be centered.
 * @return The bounding box of the text centered in the _textBounds.
 */
private RectF calcTextBounds(String _text, Paint _textPaint, RectF _textBounds) {

    Rect textBoundsTmp = new Rect();

    //get current text bounds
    _textPaint.getTextBounds(_text, 0, _text.length(), textBoundsTmp);
    float width = textBoundsTmp.left + textBoundsTmp.width();
    float height = textBoundsTmp.bottom + textBoundsTmp.height() * 0.93f; // the height of calcTextBounds is a bit to high, therefore  * 0.93
    //center in circle
    RectF textRect = new RectF();
    textRect.left = (_textBounds.left + ((_textBounds.width() - width) / 2));
    textRect.top = _textBounds.top + ((_textBounds.height() - height) / 2);
    textRect.right = textRect.left + width;
    textRect.bottom = textRect.top + height;


    return textRect;
}
 
开发者ID:VRLoser,项目名称:greendao_expand,代码行数:27,代码来源:CircleProgressView.java

示例2: getInputAitSpan

import android.graphics.Paint; //导入方法依赖的package包/类
public static ImageSpan getInputAitSpan(String name, float textsize) {
    if (TextUtils.isEmpty(name)) {
        return null;
    }
    Paint paint = new Paint();
    paint.setColor(Color.BLACK);
    paint.setAntiAlias(true);
    paint.setTextSize(textsize);
    Rect rect = new Rect();

    paint.getTextBounds(name, 0, name.length(), rect);

    // 获取字符串在屏幕上的长度
    int width = (int) (paint.measureText(name));

    final Bitmap bmp = Bitmap.createBitmap(width, rect.height(),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bmp);

    canvas.drawText(name, rect.left, rect.height() - rect.bottom, paint);

    return new ImageSpan(NimUIKit.getContext(), bmp, ImageSpan.ALIGN_BOTTOM);
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:24,代码来源:AitHelper.java

示例3: drawTextToDrawable

import android.graphics.Paint; //导入方法依赖的package包/类
public Bitmap drawTextToDrawable(@DrawableRes int resId, String text, int textSize) {
    Resources resources = _context.getResources();
    float scale = resources.getDisplayMetrics().density;
    Bitmap bitmap = getBitmapFromDrawable(resId);

    bitmap = bitmap.copy(bitmap.getConfig(), true);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.rgb(61, 61, 61));
    paint.setTextSize((int) (textSize * scale));
    paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);

    Rect bounds = new Rect();
    paint.getTextBounds(text, 0, text.length(), bounds);
    int x = (bitmap.getWidth() - bounds.width()) / 2;
    int y = (bitmap.getHeight() + bounds.height()) / 2;
    canvas.drawText(text, x, y, paint);

    return bitmap;
}
 
开发者ID:gsantner,项目名称:memetastic,代码行数:21,代码来源:ContextUtils.java

示例4: getMoreSuggestionsHint

import android.graphics.Paint; //导入方法依赖的package包/类
private static Drawable getMoreSuggestionsHint(final Resources res, final float textSize,
        final int color) {
    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setTextAlign(Align.CENTER);
    paint.setTextSize(textSize);
    paint.setColor(color);
    final Rect bounds = new Rect();
    paint.getTextBounds(MORE_SUGGESTIONS_HINT, 0, MORE_SUGGESTIONS_HINT.length(), bounds);
    final int width = Math.round(bounds.width() + 0.5f);
    final int height = Math.round(bounds.height() + 0.5f);
    final Bitmap buffer = Bitmap.createBitmap(width, (height * 3 / 2), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(buffer);
    canvas.drawText(MORE_SUGGESTIONS_HINT, width / 2, height, paint);
    BitmapDrawable bitmapDrawable = new BitmapDrawable(res, buffer);
    bitmapDrawable.setTargetDensity(canvas);
    return bitmapDrawable;
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:19,代码来源:SuggestionStripLayoutHelper.java

示例5: initPaints

import android.graphics.Paint; //导入方法依赖的package包/类
private void initPaints() {
    mTextPaint = new Paint();
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setColor(mTextColor);
    mTextPaint.setAntiAlias(true);
    mTextPaint.setDither(true);
    mTextPaint.getTextBounds(mText, 0, mText.length(), mTextRect);
    mIconPaint = new Paint();
}
 
开发者ID:JackWHLiu,项目名称:jackknife,代码行数:10,代码来源:ShadeView.java

示例6: addTextWatermark

import android.graphics.Paint; //导入方法依赖的package包/类
/**
 * 添加文字水印
 *
 * @param src      源图片
 * @param content  水印文本
 * @param textSize 水印字体大小
 * @param color    水印字体颜色
 * @param x        起始坐标x
 * @param y        起始坐标y
 * @param recycle  是否回收
 * @return 带有文字水印的图片
 */
public static Bitmap addTextWatermark(Bitmap src, String content, float textSize, int color, float x,
                                      float y, boolean recycle) {
    if (isEmptyBitmap(src) || content == null) return null;
    Bitmap ret = src.copy(src.getConfig(), true);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    Canvas canvas = new Canvas(ret);
    paint.setColor(color);
    paint.setTextSize(textSize);
    Rect bounds = new Rect();
    paint.getTextBounds(content, 0, content.length(), bounds);
    canvas.drawText(content, x, y + textSize, paint);
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
开发者ID:tututututututu,项目名称:BaseCore,代码行数:27,代码来源:ImageUtils.java

示例7: addSubmenuItem

import android.graphics.Paint; //导入方法依赖的package包/类
public void addSubmenuItem(int iconId, int titleId, long itemId) {
    // Add the item to the internal list
    mItemList.add(new SubmenuItemData(iconId, titleId, itemId));

    // Compute the width of the title 
    Paint paint = new Paint();
    Rect bounds = new Rect();
    int textWidth;

    paint.setTypeface(Typeface.DEFAULT);
    paint.setTextSize(mSubmenuFontSize);

    String title = mContext.getString(titleId);
    paint.getTextBounds(title, 0, title.length(), bounds);
    textWidth =  bounds.width();

    // Check if this is the longuest title of the submenu
    if (textWidth > mSubmenuItemTitleMaxWidth) {
        mSubmenuItemTitleMaxWidth = textWidth;
    }

    // Check if this is the widest icon of the submenu
    if (iconId>0) {
        int iconWidth = getBitmapWidth(iconId);
        if (iconWidth > mIconMaxWidth) {
            mIconMaxWidth = iconWidth;
        }
    }
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:30,代码来源:ActionBarSubmenu.java

示例8: build

import android.graphics.Paint; //导入方法依赖的package包/类
public GraphStyle build() {
          float density = context.getResources().getDisplayMetrics().density;
	Rect rect = new Rect();
	Paint namePaint = new Paint();
	Paint amountPaint = new Paint();
	Paint linePaint = new Paint();
	namePaint.setColor(Color.WHITE);
	namePaint.setAntiAlias(true);
	namePaint.setTextAlign(Align.LEFT);
	namePaint.setTextSize(spToPx(nameTextSize, density));
	namePaint.setTypeface(Typeface.DEFAULT_BOLD);
	namePaint.getTextBounds("A", 0, 1, rect);		
	int nameHeight = rect.height();
	amountPaint.setColor(Color.WHITE);
	amountPaint.setAntiAlias(true);
	amountPaint.setTextSize(spToPx(amountTextSize, density));
	amountPaint.setTextAlign(Align.CENTER);
	amountPaint.getTextBounds("8", 0, 1, rect);		
	int amountHeight = rect.height();
	linePaint.setStyle(Style.FILL);
	return new GraphStyle(
			spToPx(dy, density),
                  spToPx(textDy, density),
                  spToPx(indent, density),
			spToPx(lineHeight, density),
                  nameHeight,
                  amountHeight,
			namePaint,
                  amountPaint,
                  linePaint);
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:32,代码来源:GraphStyle.java

示例9: renderTextOnBitmap

import android.graphics.Paint; //导入方法依赖的package包/类
/**
 * Renders an arbitrary string (centered) at the bottom of the given input Bitmap. The given
 * input Bitmap will be altered and must thus be mutable.
 *
 * @param input The Bitmap on which a String should be rendered (This Bitmap must be mutable)
 * @param text The text that should be rendered.
 */
private void renderTextOnBitmap(Bitmap input, String text) {

    Canvas canvas = new Canvas(input);

    Paint paint = getBarcodePaint();

    Rect bounds = new Rect();
    paint.getTextBounds(text, 0, text.length(), bounds);
    int x = (input.getWidth() - bounds.width())/2;
    int y = input.getHeight() - 25;

    canvas.drawText(text, x, y, paint);
}
 
开发者ID:AbyxBelgium,项目名称:Loyalty,代码行数:21,代码来源:BarcodeGenerator.java

示例10: setupPaint

import android.graphics.Paint; //导入方法依赖的package包/类
private void setupPaint() {
    progressBarPaint = new Paint();
    progressBarPaint.setColor((change < 100) ? barNegativeColor : barPositiveColor);

    barBorderPaint = new Paint();
    barBorderPaint.setColor(barBorderColor);
    barBorderPaint.setStrokeWidth(barBorderThickness);
    if (shadowEnabled) {
        setLayerType(LAYER_TYPE_SOFTWARE, barBorderPaint);
        barBorderPaint.setShadowLayer(6, 2, 2, Color.parseColor("#424242"));
    }

    whitePaint = new Paint();
    whitePaint.setColor(Color.WHITE);

    textPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
    textPaint.setColor(textColor);
    textPaint.setTypeface(Typeface.create("sans-serif-condensed", Typeface.ITALIC));
    textPaint.setTextSize(UiUtils.dpToPx(14));
    textPaint.setStyle(Paint.Style.FILL);

    markerLinePaint = new Paint();
    markerLinePaint.setColor(markerLineColor);
    markerLinePaint.setStrokeWidth(UiUtils.dpToPx(2));

    Rect rect = new Rect();
    textPaint.getTextBounds("23 Mar", 0, 6, rect);
    estimatedTextWidth = rect.width();
    estimatedTextHeight = UiUtils.dpToPx(rect.height());

    extraDateHeight = estimatedTextHeight + UiUtils.dpToPx(8);
}
 
开发者ID:Protino,项目名称:CodeWatch,代码行数:33,代码来源:PerformanceBarView.java

示例11: drawTextToBitmap

import android.graphics.Paint; //导入方法依赖的package包/类
public static Bitmap drawTextToBitmap(Context gContext, int gResId, String gText) {  
    	  Log.i(TAG, "drawTextToBitmap = " + gText);
		  Resources resources = gContext.getResources();  
		  float scale = resources.getDisplayMetrics().density;  
		  Bitmap bitmap =   
		     BitmapFactory.decodeResource(resources, gResId);  
		   
		  Bitmap.Config bitmapConfig =
		      bitmap.getConfig();  
		  // set default bitmap config if none   
		 if(bitmapConfig == null) {  
		    bitmapConfig = Bitmap.Config.ARGB_8888;
		  }  
		  // resource bitmaps are imutable,    
		  // so we need to convert it to mutable one   
		  bitmap = bitmap.copy(bitmapConfig, true);  
		   
		  Canvas canvas = new Canvas(bitmap);  
		  // new antialised Paint   
		  Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);  
		  // text color - #3D3D3D   
		  paint.setColor(Color.WHITE);  
		  // text size in pixels   
		  paint.setTextSize((int) (12 * scale));  
		  // text shadow   
//		  paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);  
		   
		  // draw text to the Canvas center   
		  Rect bounds = new Rect();  
		  paint.getTextBounds(gText, 0, gText.length(), bounds);  
		  int x = (bitmap.getWidth() - bounds.width())/2;  
		  int y = (bitmap.getHeight())/2 + (int)scale*2;  
		   
		  canvas.drawText(gText,  x, y, paint);  
	      
		  canvas.save(Canvas.ALL_SAVE_FLAG); 
	      canvas.restore();
		   
		  return bitmap;  
	}
 
开发者ID:januslo,项目名称:react-native-sunmi-inner-printer,代码行数:41,代码来源:BitmapUtils.java

示例12: ChangeColorIconWithText

import android.graphics.Paint; //导入方法依赖的package包/类
/**
 * 获取自定义属性的值
 *
 * @param context
 * @param attrs
 * @param defStyleAttr
 */

public ChangeColorIconWithText(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.ChangeColorIconWithText);

    int n = a.getIndexCount();

    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);
        switch (attr) {
            case R.styleable.ChangeColorIconWithText_icon:
                BitmapDrawable drawable = (BitmapDrawable) a.getDrawable(attr);
                mIconBitmap = drawable.getBitmap();
                break;
            case R.styleable.ChangeColorIconWithText_color:
                mColor = a.getColor(attr, 0x03a9f4);
                break;
            case R.styleable.ChangeColorIconWithText_text:
                mText = a.getString(attr);
                break;
            case R.styleable.ChangeColorIconWithText_text_size:
                mTextSize = (int) a.getDimension(attr, TypedValue
                        .applyDimension(TypedValue.COMPLEX_UNIT_SP, 12,
                                getResources().getDisplayMetrics()));
                break;
        }
    }

    a.recycle();

    mTextBound = new Rect();
    mTextPaint = new Paint();
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setColor(0Xff555555);
    mTextPaint.getTextBounds(mText, 0, mText.length(), mTextBound);
}
 
开发者ID:chenlindev,项目名称:beyondwords,代码行数:45,代码来源:ChangeColorIconWithText.java

示例13: generateDefaultAvatar

import android.graphics.Paint; //导入方法依赖的package包/类
public static String generateDefaultAvatar(String username, String userid) {

        String s = null;
        if (!TextUtils.isEmpty(username)) {
            s = String.valueOf(username.charAt(0));
        }
        if (s == null) {
            s = "A";
        }
        String color = getColorRGB(userid);
        String string = getAllFirstLetter(username);
        createDir(SAVEADDRESS);
        File f = new File(SAVEADDRESS, string + "_" + userid);
        if (f.exists()) {
            return SCHEMA + f.getPath();
        }
        Paint paint = new Paint();
        paint.setColor(Color.WHITE);
        paint.setTextSize(220);
        paint.setAntiAlias(true);
        int width = 480;
        int height = 480;
        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawColor(Color.parseColor(color));
        Rect rect = new Rect();
        paint.getTextBounds(s, 0, s.length(), rect);
        Paint.FontMetrics fm = paint.getFontMetrics();
        int textLeft = (int) ((width - paint.measureText(s)) / 2);
        int textTop = (int) (height - width / 2 + Math.abs(fm.ascent) / 2 - 25);
        canvas.drawText(s, textLeft, textTop, paint);
        return saveBitmap(bitmap, string + "_" + userid);
    }
 
开发者ID:lo625090140,项目名称:lqrwechatrongcloud,代码行数:34,代码来源:RongGenerate.java

示例14: getStringWidth

import android.graphics.Paint; //导入方法依赖的package包/类
public static float getStringWidth(final String string, final Paint paint) {
    synchronized (sStringWidthBounds) {
        paint.getTextBounds(string, 0, string.length(), sStringWidthBounds);
        return sStringWidthBounds.width();
    }
}
 
开发者ID:rkkr,项目名称:simple-keyboard,代码行数:7,代码来源:TypefaceUtils.java

示例15: getTextWidth

import android.graphics.Paint; //导入方法依赖的package包/类
private int getTextWidth(String str, Paint paint) {
    paint.getTextBounds(str, 0, str.length(), mBounds);
    return mBounds.width();
}
 
开发者ID:aquarius520,项目名称:LotteryView,代码行数:5,代码来源:LotteryView.java


注:本文中的android.graphics.Paint.getTextBounds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。