Example usage for android.graphics Canvas drawText

List of usage examples for android.graphics Canvas drawText

Introduction

In this page you can find the example usage for android.graphics Canvas drawText.

Prototype

public void drawText(@NonNull String text, float x, float y, @NonNull Paint paint) 

Source Link

Document

Draw the text, with origin at (x,y), using the specified paint.

Usage

From source file:net.networksaremadeofstring.rhybudd.ZenossWidgetGraph.java

private Bitmap RenderBarGraph(int CritCount, int ErrCount, int WarnCount) {

    //Log.i("Counts", Integer.toString(CritCount) + " / " + Integer.toString(ErrCount) + " / " + Integer.toString(WarnCount));
    Bitmap emptyBmap = Bitmap.createBitmap(290, 150, Config.ARGB_8888);

    int width = emptyBmap.getWidth();
    int height = emptyBmap.getHeight();
    Bitmap charty = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(charty);
    //final int color = 0xff0B0B61; 
    final Paint paint = new Paint();

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.WHITE);/*from ww w .ja  v  a 2 s . c  om*/

    //y
    canvas.drawLine(25, 0, 25, 289, paint);
    //x
    canvas.drawLine(25, 149, 289, 149, paint);

    paint.setAntiAlias(true);
    int Max = 0;

    if (CritCount > ErrCount && CritCount > WarnCount)
        Max = CritCount;
    else if (ErrCount > CritCount && ErrCount > WarnCount)
        Max = ErrCount;
    else if (WarnCount > CritCount && WarnCount > ErrCount)
        Max = WarnCount;
    else
        Max = CritCount;

    if (Max > 0)
        canvas.drawText(Integer.toString(Max), 0, 10, paint);

    if (Max > 1)
        canvas.drawText(Integer.toString(Max / 2), 0, 75, paint);

    canvas.drawText("0", 0, 148, paint);

    double divisor = 148 / (double) Max;

    paint.setAlpha(128);

    Rect rect = new Rect(32, (int) (148 - (divisor * CritCount)), 64, 148);
    paint.setColor(Color.argb(200, 208, 0, 0)); //red

    if (CritCount > 0)
        canvas.drawRect(new RectF(rect), paint);

    rect = new Rect(128, (int) (148 - (divisor * ErrCount)), 160, 148);
    paint.setColor(Color.argb(200, 255, 102, 0));//orange

    if (ErrCount > 0)
        canvas.drawRect(new RectF(rect), paint);

    rect = new Rect(224, (int) (148 - (divisor * WarnCount)), 256, 148);
    paint.setColor(Color.argb(200, 255, 224, 57)); //yellow
    if (WarnCount > 0)
        canvas.drawRect(new RectF(rect), paint);

    //Return
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    charty.compress(CompressFormat.PNG, 50, out);

    return BitmapFactory.decodeByteArray(out.toByteArray(), 0, out.size());
}

From source file:com.mappn.gfan.ui.HomeTabActivity.java

private Bitmap drawText(DisplayMetrics dm, Resources res, Bitmap bm, int num) {
    final int height = bm.getScaledHeight(dm);
    final int width = bm.getScaledWidth(dm);
    Bitmap newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    canvas.drawBitmap(bm, new Matrix(), new Paint());
    Paint textPainter = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPainter.setColor(res.getColor(R.color.tab_app_num));
    textPainter.setTextSize(dm.scaledDensity * 12);
    textPainter.setTypeface(Typeface.DEFAULT_BOLD);
    float textWidth = textPainter.measureText(String.valueOf(num)) / 2;
    canvas.drawText(String.valueOf(num), width / 2 - textWidth, height / 2 + (dm.scaledDensity * 6),
            textPainter);/* www.j  ava 2s .c  o  m*/
    canvas.save();
    return newBitmap;
}

From source file:com.cssweb.android.view.FinanceMini.java

public void drawIndex(Canvas canvas) {
    //canvas.restore();
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);/* w ww.  j  ava2s .  c  om*/
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setTextSize(mTextSize);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("???", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width, -DY * 5);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("a"), true), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("b"), true), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("govbond"), true), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("fund"), true), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("warrant"), true), x, y, paint);
            canvas.translate(0, DY);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("bond"), true), x, y, paint);

        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}

From source file:com.cssweb.android.view.FinanceMini.java

public void drawHKPrice(Canvas canvas) {
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);//from   w  w  w .j av  a  2 s  .c o  m
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setTextSize(mTextSize);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(width / 2, -DY * 4);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x - tips, y, paint);
            canvas.translate(0, DY);
            //            if(jo.getDouble("wb")<0)
            //               paint.setColor(GlobalColor.colorPriceDown);
            //            else if(jo.getDouble("wb")>0)
            //               paint.setColor(GlobalColor.colorpriceUp);
            //            else 
            //               paint.setColor(GlobalColor.colorPriceEqual);
            //            canvas.drawText(Utils.dataFormation(jo.getDouble("wb")*100, 1)+"%", x-tips, y, paint);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("cjje"), false), x - tips, y, paint);
            paint.setColor(GlobalColor.colorpriceUp);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x - tips, y, paint);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("msgs"), true), x - tips, y, paint);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, -DY * 3);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            //            canvas.drawText("", x, y, paint);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            //            canvas.translate(0, DY);
            //            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            canvas.translate(width / 2, -DY * 3);
            paint.setColor(GlobalColor.colorStockName);
            canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1, jo.getInt("tp")), x - tips, y, paint);
            canvas.translate(0, DY);
            //            if(jo.getDouble("wc")<0) {
            //               paint.setColor(GlobalColor.colorPriceDown);
            //               canvas.drawText("-" + Utils.getAmountFormat(Math.abs(jo.getDouble("wc")), true), x-tips, y, paint);
            //            }
            //            else if(jo.getDouble("wc")>0) {
            //               paint.setColor(GlobalColor.colorpriceUp);
            //               canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x-tips, y, paint);
            //            }
            //            else {
            //               paint.setColor(GlobalColor.colorPriceEqual);
            //               canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x-tips, y, paint);
            //            }
            paint.setColor(GlobalColor.colorPriceDown);
            canvas.drawText("", x - tips, y, paint);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint);
            //            paint.setColor(GlobalColor.colorStockName);
            //            canvas.translate(0, DY);
            //            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x-tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}

From source file:airfree.xprojets.airfree.PinView.java

@Override
public void draw(Canvas canvas) {
    canvas.drawCircle(mX, mY, mCircleRadiusPx, mCirclePaint);
    //Draw pin if pressed
    if (mPinRadiusPx > 0 && (mHasBeenPressed || !mPinsAreTemporary)) {
        mBounds.set((int) mX - mPinRadiusPx, (int) mY - (mPinRadiusPx * 2) - (int) mPinPadding,
                (int) mX + mPinRadiusPx, (int) mY - (int) mPinPadding);
        mPin.setBounds(mBounds);/*  w  w  w . j  a va2  s .c om*/
        String text = mValue;

        if (this.formatter != null) {
            text = formatter.format(text);
        }

        calibrateTextSize(mTextPaint, text, mBounds.width());
        mTextPaint.getTextBounds(text, 0, text.length(), mBounds);
        mTextPaint.setTextAlign(Paint.Align.CENTER);
        mPin.setColorFilter(mPinFilter);
        mPin.draw(canvas);
        canvas.drawText(text, mX, mY - mPinRadiusPx - mPinPadding + mTextYPadding, mTextPaint);
    }
    super.draw(canvas);
}

From source file:com.android.contacts.common.ContactPhotoManager.java

/**
 * If necessary, decodes bytes stored in the holder to Bitmap.  As long as the
 * bitmap is held either by {@link #mBitmapCache} or by a soft reference in
 * the holder, it will not be necessary to decode the bitmap.
 *///from w w  w.  ja  v  a  2  s  . c o m
private static void inflateBitmap(BitmapHolder holder, int requestedExtent) {
    final int sampleSize = BitmapUtil.findOptimalSampleSize(holder.originalSmallerExtent, requestedExtent);
    byte[] bytes = holder.bytes;
    if (bytes == null || bytes.length == 0) {
        return;
    }

    if (sampleSize == holder.decodedSampleSize) {
        // Check the soft reference.  If will be retained if the bitmap is also
        // in the LRU cache, so we don't need to check the LRU cache explicitly.
        if (holder.bitmapRef != null) {
            holder.bitmap = holder.bitmapRef.get();
            if (holder.bitmap != null) {
                return;
            }
        }
    }

    try {
        Bitmap bitmap = BitmapUtil.decodeBitmapFromBytes(bytes, sampleSize);

        // TODO: As a temporary workaround while framework support is being added to
        // clip non-square bitmaps into a perfect circle, manually crop the bitmap into
        // into a square if it will be displayed as a thumbnail so that it can be cropped
        // into a circle.
        final int height = bitmap.getHeight();
        final int width = bitmap.getWidth();

        // The smaller dimension of a scaled bitmap can range from anywhere from 0 to just
        // below twice the length of a thumbnail image due to the way we calculate the optimal
        // sample size.
        if (height != width && Math.min(height, width) <= mThumbnailSize * 2) {
            final int dimension = Math.min(height, width);
            bitmap = ThumbnailUtils.extractThumbnail(bitmap, dimension, dimension);
        }
        // make bitmap mutable and draw size onto it
        if (DEBUG_SIZES) {
            Bitmap original = bitmap;
            bitmap = bitmap.copy(bitmap.getConfig(), true);
            original.recycle();
            Canvas canvas = new Canvas(bitmap);
            Paint paint = new Paint();
            paint.setTextSize(16);
            paint.setColor(Color.BLUE);
            paint.setStyle(Style.FILL);
            canvas.drawRect(0.0f, 0.0f, 50.0f, 20.0f, paint);
            paint.setColor(Color.WHITE);
            paint.setAntiAlias(true);
            canvas.drawText(bitmap.getWidth() + "/" + sampleSize, 0, 15, paint);
        }

        holder.decodedSampleSize = sampleSize;
        holder.bitmap = bitmap;
        holder.bitmapRef = new SoftReference<Bitmap>(bitmap);
        if (DEBUG) {
            Log.d(TAG, "inflateBitmap " + btk(bytes.length) + " -> " + bitmap.getWidth() + "x"
                    + bitmap.getHeight() + ", " + btk(bitmap.getByteCount()));
        }
    } catch (OutOfMemoryError e) {
        // Do nothing - the photo will appear to be missing
    }
}

From source file:com.example.ysh.myapplication.view.readview.PageFactory.java

/**
 * ?/*from   ww  w  . j  av a2s . c o m*/
 *
 * @param canvas
 */
public synchronized void onDraw(Canvas canvas) {
    if (mLines.size() == 0) {
        curEndPos = curBeginPos;
        mLines = pageDown();
    }
    if (mLines.size() > 0) {
        int y = marginHeight + (mLineSpace << 1);
        // 
        if (mBookPageBg != null) {
            canvas.drawBitmap(mBookPageBg, null, rectF, null);
        } else {
            canvas.drawColor(Color.WHITE);
        }
        // 
        canvas.drawText(chaptersList.get(currentChapter - 1).title, marginWidth, y, mTitlePaint);
        y += mLineSpace + mNumFontSize;
        // ?
        for (String line : mLines) {
            y += mLineSpace;
            if (line.endsWith("@")) {
                canvas.drawText(line.substring(0, line.length() - 1), marginWidth, y, mPaint);
                y += mLineSpace;
            } else {
                canvas.drawText(line, marginWidth, y, mPaint);
            }
            y += mFontSize;
        }
        // ??
        if (batteryBitmap != null) {
            canvas.drawBitmap(batteryBitmap, marginWidth + 2,
                    mHeight - marginHeight - ScreenUtils.dpToPxInt(12), mTitlePaint);
        }

        float percent = (float) currentChapter * 100 / chapterSize;
        canvas.drawText(decimalFormat.format(percent) + "%", (mWidth - percentLen) / 2, mHeight - marginHeight,
                mTitlePaint);

        String mTime = dateFormat.format(new Date());
        canvas.drawText(mTime, mWidth - marginWidth - timeLen, mHeight - marginHeight, mTitlePaint);

        // ?
        SettingManager.getInstance().saveReadProgress(bookId, currentChapter, curBeginPos, curEndPos);
    }
}

From source file:com.cssweb.android.view.FinanceMini.java

private void drawQihuo(Canvas canvas) {
    Paint paint = this.mPaint;
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setAntiAlias(true);// w w w .j  av  a2s .co  m
    if (quoteData != null) {
        try {
            JSONArray jArr = quoteData.getJSONArray("data");
            JSONObject jo = jArr.getJSONObject(0);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setTextSize(mTextSize);
            paint.setColor(GlobalColor.colorLabelName);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            //            canvas.translate(0, DY);
            //            canvas.drawText(" ", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(width / 2, -DY * 4);
            canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x - tips, y, paint);

            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jrjs"), stockdigit, jo.getInt("tp")), x - tips, y,
                    paint);

            paint.setColor(GlobalColor.colorpriceUp);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("zt"), stockdigit, jo.getInt("tp")), x - tips, y,
                    paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("jrcc"), 0, jo.getInt("tp")), x - tips, y, paint);

            //            canvas.translate(0, DY);
            //            canvas.drawText(Utils.dataFormation(jo.getDouble("jrkc"), 0), x-tips, y, paint);

            paint.setColor(GlobalColor.colorpriceUp);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x, y, paint);

            canvas.translate(0, -DY * 4);

            paint.setTextAlign(Paint.Align.LEFT);
            paint.setColor(GlobalColor.colorLabelName);

            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("?", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);
            //            canvas.translate(0, DY);
            //            canvas.drawText(" ", x, y, paint);
            canvas.translate(0, DY);
            canvas.drawText("", x, y, paint);

            canvas.translate(width / 2, -DY * 5);

            paint.setTextAlign(Paint.Align.RIGHT);
            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), false), x - tips, y, paint);

            paint.setColor(GlobalColor.colorPriceEqual);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("zrjs"), stockdigit, jo.getInt("tp")), x - tips, y,
                    paint);

            paint.setColor(GlobalColor.colorPriceDown);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("dt"), stockdigit, jo.getInt("tp")), x - tips, y,
                    paint);

            paint.setColor(GlobalColor.colorStockName);
            canvas.translate(0, DY);
            canvas.drawText(Utils.dataFormation(jo.getDouble("zc"), 0, jo.getInt("tp")), x - tips, y, paint);

            //            paint.setColor(GlobalColor.colorStockName);
            //            canvas.translate(0, DY);
            //            canvas.drawText(Utils.dataFormation(jo.getDouble("jrpc"), 0), x-tips, y, paint);   

            paint.setColor(GlobalColor.colorPriceDown);
            canvas.translate(0, DY);
            canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint);
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
        }
    }
}

From source file:com.apache.fastandroid.novel.view.readview.PageFactory.java

/**
 * ?//from   w  ww  . java 2 s .c  om
 *
 * @param canvas
 */
public synchronized void onDraw(Canvas canvas) {
    if (mLines.size() == 0) {
        curEndPos = curBeginPos;
        mLines = pageDown();
    }
    if (mLines.size() > 0) {
        int y = marginHeight + (mLineSpace << 1);
        // 
        if (mBookPageBg != null) {
            canvas.drawBitmap(mBookPageBg, null, rectF, null);
        } else {
            canvas.drawColor(Color.WHITE);
        }
        // 
        canvas.drawText(chaptersList.get(currentChapter - 1).title, marginWidth, y, mTitlePaint);
        y += mLineSpace + mNumFontSize;
        // ?
        for (String line : mLines) {
            y += mLineSpace;
            if (line.endsWith("@")) {
                canvas.drawText(line.substring(0, line.length() - 1), marginWidth, y, mPaint);
                y += mLineSpace;
            } else {
                canvas.drawText(line, marginWidth, y, mPaint);
            }
            y += mFontSize;
        }
        // ??
        if (batteryBitmap != null) {
            canvas.drawBitmap(batteryBitmap, marginWidth + 2,
                    mHeight - marginHeight - DimensUtil.dp2px(mContext, 12), mTitlePaint);
        }

        float percent = (float) currentChapter * 100 / chapterSize;
        canvas.drawText(decimalFormat.format(percent) + "%", (mWidth - percentLen) / 2, mHeight - marginHeight,
                mTitlePaint);

        String mTime = dateFormat.format(new Date());
        canvas.drawText(mTime, mWidth - marginWidth - timeLen, mHeight - marginHeight, mTitlePaint);

        // ?
        SettingManager.getInstance().saveReadProgress(bookId, currentChapter, curBeginPos, curEndPos);
    }
}

From source file:com.gruporaido.tasker_library.util.Helper.java

/**
 * @param drawableId/*from  ww w .j  a  v a2 s . co m*/
 * @param text
 * @param textSize
 * @param offsetX
 * @param offsetY
 * @return
 */
public Bitmap drawTextOnDrawable(int drawableId, String text, int textSize, int offsetX, int offsetY) {

    Bitmap bm = BitmapFactory.decodeResource(mContext.getResources(), drawableId).copy(Bitmap.Config.ARGB_8888,
            true);

    Typeface tf = Typeface.create("Helvetica", Typeface.BOLD);

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.WHITE);
    paint.setTypeface(tf);
    paint.setTextAlign(Paint.Align.CENTER);
    paint.setTextSize(dpToPx(textSize));

    Rect textRect = new Rect();
    paint.getTextBounds(text, 0, text.length(), textRect);

    Canvas canvas = new Canvas(bm);

    //If the text is bigger than the canvas , reduce the font size
    if (textRect.width() >= (canvas.getWidth() - 4)) //the padding on either sides is considered as 4, so as to appropriately fit in the text
        paint.setTextSize(dpToPx(textSize / 2)); //Scaling needs to be used for different dpi's

    //Calculate the positions
    int xPos = (canvas.getWidth() / 2) - 2 + dpToPx(offsetX); //-2 is for regulating the x position offset

    //"- ((paint.descent() + paint.ascent()) / 2)" is the distance from the baseline to the center.
    int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2)) + dpToPx(offsetY);

    canvas.drawText(text, xPos, yPos, paint);

    return bm;
}