Example usage for android.graphics Bitmap getScaledWidth

List of usage examples for android.graphics Bitmap getScaledWidth

Introduction

In this page you can find the example usage for android.graphics Bitmap getScaledWidth.

Prototype

public int getScaledWidth(int targetDensity) 

Source Link

Document

Convenience method that returns the width of this bitmap divided by the density scale factor.

Usage

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);//from  www . ja  v a  2  s. c om
    canvas.save();
    return newBitmap;
}

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

private Bitmap drawBitmap(DisplayMetrics dm, Bitmap background, Bitmap corner) {
    Canvas canvas = new Canvas();
    final int height = background.getScaledHeight(dm);
    final int width = background.getScaledWidth(dm);
    Bitmap smallBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    canvas.setBitmap(smallBitmap);//from   w  w w  .  j av a2 s  .  c o  m
    Paint textPainter = new Paint(Paint.ANTI_ALIAS_FLAG);
    canvas.drawBitmap(background, 0, 0, textPainter);
    textPainter.setXfermode(new PorterDuffXfermode(Mode.SRC_OVER));
    canvas.drawBitmap(corner, width - corner.getScaledWidth(dm), 0, textPainter);
    canvas.save();
    return smallBitmap;
}

From source file:com.rexmtorres.android.patternlock.PatternLockView.java

/**
 * @param partOfPattern Whether this circle is part of the pattern.
 *///from   w  w  w.  j ava2 s  . co  m
private void drawDot(Canvas canvas, float centerX, float centerY, float radius, boolean partOfPattern,
        float alpha, Bitmap oDotBitmap) {
    mPaint.setColor(getCurrentColor(partOfPattern));
    mPaint.setAlpha((int) (alpha * 255));

    // If the bitmap is set, draw it.  If not, draw a circle.
    if (oDotBitmap != null) {
        float nBitmapCenterX = centerX - (oDotBitmap.getScaledHeight(canvas) / 2f);
        float nBitmapCenterY = centerY - (oDotBitmap.getScaledWidth(canvas) / 2f);

        canvas.drawBitmap(oDotBitmap, nBitmapCenterX, nBitmapCenterY, mPaint);
    } else {
        canvas.drawCircle(centerX, centerY, radius, mPaint);
    }
}