Example usage for android.graphics Bitmap getScaledHeight

List of usage examples for android.graphics Bitmap getScaledHeight

Introduction

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

Prototype

public int getScaledHeight(int targetDensity) 

Source Link

Document

Convenience method that returns the height 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);/*  w ww. j av a2  s  .  c o  m*/
    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 ww .  j  a  va 2 s.  c  om
    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 ww . j  a  v a 2  s.c om
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);
    }
}