Java Code Examples for android.graphics.Bitmap#getScaledWidth()

The following examples show how to use android.graphics.Bitmap#getScaledWidth() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
public SelectableRoundedCornerDrawable(Bitmap bitmap, Resources r) {
    mBitmap = bitmap;
    mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

    if (bitmap != null) {
        mBitmapWidth = bitmap.getScaledWidth(r.getDisplayMetrics());
        mBitmapHeight = bitmap.getScaledHeight(r.getDisplayMetrics());
    } else {
        mBitmapWidth = mBitmapHeight = -1;
    }

    mBitmapRect.set(0, 0, mBitmapWidth, mBitmapHeight);

    mBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBitmapPaint.setStyle(Paint.Style.FILL);
    mBitmapPaint.setShader(mBitmapShader);

    mBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBorderPaint.setStyle(Paint.Style.STROKE);
    mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR));
    mBorderPaint.setStrokeWidth(mBorderWidth);
}
 
Example 2
public SelectableRoundedCornerDrawable(Bitmap bitmap, Resources r) {
    mBitmap = bitmap;
    mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

    if (bitmap != null) {
        mBitmapWidth = bitmap.getScaledWidth(r.getDisplayMetrics());
        mBitmapHeight = bitmap.getScaledHeight(r.getDisplayMetrics());
    } else {
        mBitmapWidth = mBitmapHeight = -1;
    }

    mBitmapRect.set(0, 0, mBitmapWidth, mBitmapHeight);

    mBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBitmapPaint.setStyle(Paint.Style.FILL);
    mBitmapPaint.setShader(mBitmapShader);

    mBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBorderPaint.setStyle(Paint.Style.STROKE);
    mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR));
    mBorderPaint.setStrokeWidth(mBorderWidth);
}
 
Example 3
public SelectableRoundedCornerDrawable(Bitmap bitmap, Resources r) {
    mBitmap = bitmap;
    mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

    if (bitmap != null) {
        mBitmapWidth = bitmap.getScaledWidth(r.getDisplayMetrics());
        mBitmapHeight = bitmap.getScaledHeight(r.getDisplayMetrics());
    } else {
        mBitmapWidth = mBitmapHeight = -1;
    }

    mBitmapRect.set(0, 0, mBitmapWidth, mBitmapHeight);

    mBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBitmapPaint.setStyle(Paint.Style.FILL);
    mBitmapPaint.setShader(mBitmapShader);

    mBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBorderPaint.setStyle(Paint.Style.STROKE);
    mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR));
    mBorderPaint.setStrokeWidth(mBorderWidth);
}
 
Example 4
public SelectableRoundedCornerDrawable(Bitmap bitmap, Resources r) {
    mBitmap = bitmap;
    mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

    if (bitmap != null) {
        mBitmapWidth = bitmap.getScaledWidth(r.getDisplayMetrics());
        mBitmapHeight = bitmap.getScaledHeight(r.getDisplayMetrics());
    } else {
        mBitmapWidth = mBitmapHeight = -1;
    }

    mBitmapRect.set(0, 0, mBitmapWidth, mBitmapHeight);

    mBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBitmapPaint.setStyle(Paint.Style.FILL);
    mBitmapPaint.setShader(mBitmapShader);

    mBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBorderPaint.setStyle(Paint.Style.STROKE);
    mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR));
    mBorderPaint.setStrokeWidth(mBorderWidth);
}
 
Example 5
Source Project: ChatKit   File: RoundedImageView.java    License: Apache License 2.0 5 votes vote down vote up
private RoundedCornerDrawable(Bitmap bitmap, Resources r) {
    mBitmap = bitmap;
    mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

    mBitmapWidth = bitmap.getScaledWidth(r.getDisplayMetrics());
    mBitmapHeight = bitmap.getScaledHeight(r.getDisplayMetrics());

    mBitmapRect.set(0, 0, mBitmapWidth, mBitmapHeight);

    mBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBitmapPaint.setStyle(Paint.Style.FILL);
    mBitmapPaint.setShader(mBitmapShader);
}
 
Example 6
private void drawPage(PdfDocument.Page page) {
    SQRLStorage storage = SQRLStorage.getInstance(activity);
    Canvas canvas = page.getCanvas();
    int marginLeftRight = 35;
    int marginTop = 65;
    int lastBlockY = marginTop;

    TextPaint headlineTextPaint = new TextPaint();
    headlineTextPaint.setTextSize(16);
    headlineTextPaint.setFakeBoldText(true);

    TextPaint bodyTextPaint = new TextPaint();
    bodyTextPaint.setTextSize(12);

    TextPaint identityTextTextPaint = new TextPaint(bodyTextPaint);
    identityTextTextPaint.setTypeface(Typeface.MONOSPACE);
    identityTextTextPaint.setFakeBoldText(true);

    String identityTitle = "\"" + identityName + "\" SQRL Identity";

    lastBlockY += DocumentPrintUtils.drawTextBlock(
            canvas,
            identityTitle,
            Layout.Alignment.ALIGN_CENTER,
            headlineTextPaint,
            marginTop,
            marginLeftRight);

    lastBlockY += DocumentPrintUtils.drawTextBlock(
            canvas,
            activity.getString(R.string.print_identity_desc1),
            Layout.Alignment.ALIGN_NORMAL,
            bodyTextPaint,
            lastBlockY + 20,
            marginLeftRight) + 20;

    byte[] saveData;
    if(this.withoutPassword) {
        saveData = storage.createSaveDataWithoutPassword();
    } else {
        saveData = storage.createSaveData();
    }

    int canvasMiddle = canvas.getWidth() / 2;
    QrCode qrCode = QrCode.encodeBinary(saveData, QrCode.Ecc.MEDIUM);
    Bitmap bitmap = qrCode.toImage(3, 0);

    int bitmapWidth = bitmap.getScaledWidth(canvas);

    canvas.drawBitmap(bitmap, canvasMiddle - (bitmapWidth / 2), lastBlockY + 20, new Paint());

    lastBlockY += bitmap.getScaledHeight(canvas) + 20;

    lastBlockY += DocumentPrintUtils.drawTextBlock(
            canvas,
            activity.getString(R.string.print_identity_desc2),
            Layout.Alignment.ALIGN_NORMAL,
            bodyTextPaint,
            lastBlockY + 20,
            marginLeftRight) + 30;


    int i = 0;
    try {
        Utils.refreshStorageFromDb(activity);
        for (String identityTextBlock : storage.getVerifyingRecoveryBlock().split("\n")) {
            lastBlockY += DocumentPrintUtils.drawTextBlock(
                    canvas,
                    identityTextBlock,
                    Layout.Alignment.ALIGN_CENTER,
                    identityTextTextPaint,
                    lastBlockY + 3,
                    marginLeftRight) + 3;
            i++;
        }
    } catch (Exception e) {
        Log.e(TAG, e.getMessage(), e);
    }

    DocumentPrintUtils.drawTextBlock(
            canvas,
            activity.getString(R.string.print_identity_desc3),
            Layout.Alignment.ALIGN_NORMAL,
            bodyTextPaint,
            lastBlockY + 20,
            marginLeftRight);

    DocumentPrintUtils.drawPrintPageFooter(activity, canvas);
}