當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。