Example usage for android.support.v4.graphics.drawable RoundedBitmapDrawable setBounds

List of usage examples for android.support.v4.graphics.drawable RoundedBitmapDrawable setBounds

Introduction

In this page you can find the example usage for android.support.v4.graphics.drawable RoundedBitmapDrawable setBounds.

Prototype

public void setBounds(@NonNull Rect bounds) 

Source Link

Document

Specify a bounding rectangle for the Drawable.

Usage

From source file:com.android.contacts.common.list.ShortcutIntentBuilder.java

private Bitmap generateQuickContactIcon(Drawable photo) {

    // Setup the drawing classes
    Bitmap bitmap = Bitmap.createBitmap(mIconSize, mIconSize, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    // Copy in the photo
    Rect dst = new Rect(0, 0, mIconSize, mIconSize);
    photo.setBounds(dst);//from  www .  j  a  v  a 2 s.c o m
    photo.draw(canvas);

    // Draw the icon with a rounded border
    RoundedBitmapDrawable roundedDrawable = RoundedBitmapDrawableFactory.create(mResources, bitmap);
    roundedDrawable.setAntiAlias(true);
    roundedDrawable.setCornerRadius(mIconSize / 2);
    Bitmap roundedBitmap = Bitmap.createBitmap(mIconSize, mIconSize, Bitmap.Config.ARGB_8888);
    canvas.setBitmap(roundedBitmap);
    roundedDrawable.setBounds(dst);
    roundedDrawable.draw(canvas);
    canvas.setBitmap(null);

    return roundedBitmap;
}

From source file:com.android.contacts.ShortcutIntentBuilder.java

private Bitmap generateQuickContactIcon(Drawable photo) {
    // Setup the drawing classes
    Bitmap bitmap = Bitmap.createBitmap(mIconSize, mIconSize, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    // Copy in the photo
    Rect dst = new Rect(0, 0, mIconSize, mIconSize);
    photo.setBounds(dst);//  w  w w . j a  v a2  s .  c o  m
    photo.draw(canvas);

    // Don't put a rounded border on an icon for O
    if (BuildCompat.isAtLeastO()) {
        return bitmap;
    }

    // Draw the icon with a rounded border
    RoundedBitmapDrawable roundedDrawable = RoundedBitmapDrawableFactory.create(mResources, bitmap);
    roundedDrawable.setAntiAlias(true);
    roundedDrawable.setCornerRadius(mIconSize / 2);
    Bitmap roundedBitmap = Bitmap.createBitmap(mIconSize, mIconSize, Bitmap.Config.ARGB_8888);
    canvas.setBitmap(roundedBitmap);
    roundedDrawable.setBounds(dst);
    roundedDrawable.draw(canvas);
    canvas.setBitmap(null);

    return roundedBitmap;
}