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

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

Introduction

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

Prototype

public void draw(Canvas canvas) 

Source Link

Usage

From source file:com.ticketmaster.servos.util.picasso.RoundedBitmapTransform.java

@Override
public Bitmap transform(Bitmap source) {
    RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(res, source);
    drawable.setCornerRadius(getCornerRadius(source));
    Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), source.getConfig());
    Canvas canvas = new Canvas(output);
    drawable.setAntiAlias(true);//from w w w  .java2s .  c o m
    drawable.setBounds(0, 0, source.getWidth(), source.getHeight());
    drawable.draw(canvas);
    if (source != output) {
        source.recycle();
    }
    return output;
}

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);/*w ww. j av  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);/*from   w  ww .  j  a  v a2s  .  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;
}

From source file:bruce.kk.imglibcompare.glide.GlideActivity.java

@OnClick({ R.id.btn_load_local, R.id.btn_load_url, R.id.btn_load_cancel })
public void onClick(View view) {
    switch (view.getId()) {
    case R.id.btn_load_local:
        Glide.with(GlideActivity.this).load(R.mipmap.ic_loading).into(ivImg);
        break;/*from   w  ww .j  a  v a 2  s  . c  om*/
    case R.id.btn_load_url:
        Glide.with(GlideActivity.this).load(ImgConstant.GIF_URL).centerCrop().placeholder(R.mipmap.ic_loading2)
                .error(R.mipmap.ic_failed)
                //  tansform 
                .transform(new BitmapTransformation(GlideActivity.this) {
                    @Override
                    protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth,
                            int outHeight) {
                        RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getResources(),
                                toTransform);
                        drawable.setCornerRadius(20);
                        //                             drawable.setCircular(true); // ?
                        // ? 
                        int width = drawable.getIntrinsicWidth();
                        int height = drawable.getIntrinsicHeight();
                        // ??
                        Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE
                                ? Bitmap.Config.ARGB_8888
                                : Bitmap.Config.RGB_565;
                        //  bitmap
                        Bitmap bitmap = Bitmap.createBitmap(width, height, config);
                        Canvas canvas = new Canvas(bitmap);
                        drawable.setBounds(0, 0, width, height);
                        drawable.draw(canvas);
                        return bitmap;
                    }

                    @Override
                    public String getId() {
                        return "1001";
                    }
                }).crossFade().listener(new RequestListener<String, GlideDrawable>() {
                    @Override
                    public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                            boolean isFirstResource) {
                        LogDetails.i("model: %s\ntarget: %s\nisFirstResource: %s\nException: %s", model, target,
                                isFirstResource, e);
                        target.onLoadFailed(new Exception("load failed, please check your code"),
                                getResources().getDrawable(R.mipmap.ic_failed));
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(GlideDrawable resource, String model,
                            Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                        LogDetails.i(
                                "model: %s\ntarget: %s\nisFirstResource: %s\nisFromMemoryCache: %s\nresource: %s",
                                model, target, isFirstResource, isFromMemoryCache, resource);
                        target.onLoadStarted(getResources().getDrawable(R.mipmap.ic_start));
                        return false;
                    }
                }).into(ivImg);
        break;
    case R.id.btn_load_cancel:
        Glide.clear(ivImg);
        break;
    }
}

From source file:bruce.kk.imglibcompare.picasso.PicassoActivity.java

@OnClick({ R.id.btn_load_local, R.id.btn_load_url, R.id.btn_load_cancel })
public void onClick(View view) {
    switch (view.getId()) {
    case R.id.btn_load_local:
        Picasso.with(PicassoActivity.this).load(R.mipmap.ic_loading).into(ivImg);
        break;/* w w w.ja  v  a 2  s .c om*/
    case R.id.btn_load_url:
        // 
        //                Picasso.with(PicassoActivity.this)
        //                       .load(ImgConstant.IMG_URL)
        //                       .resize(80, 80)
        //                       .error(R.mipmap.ic_failed)
        //                       .into(ivImg);
        // 
        Picasso.Builder builder = new Picasso.Builder(PicassoActivity.this);
        builder.listener(new Picasso.Listener() {
            @Override
            public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
                LogDetails.d(" exception: " + exception);
            }
        });
        builder.build().load(ImgConstant.IMG_URL)
                //                       .load("http://dd.com/ssss.jpg")
                .placeholder(R.mipmap.ic_loading2).error(R.mipmap.ic_failed)
                //  tansform 
                .transform(new Transformation() {
                    @Override
                    public Bitmap transform(Bitmap source) {
                        RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getResources(),
                                source);
                        drawable.setCornerRadius(50);
                        //                             drawable.setCircular(true); // ?
                        // ? 
                        int width = drawable.getIntrinsicWidth();
                        int height = drawable.getIntrinsicHeight();
                        // ??
                        Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE
                                ? Bitmap.Config.ARGB_8888
                                : Bitmap.Config.RGB_565;
                        //  bitmap
                        Bitmap bitmap = Bitmap.createBitmap(width, height, config);
                        if (bitmap != source) {
                            source.recycle();
                        }
                        Canvas canvas = new Canvas(bitmap);
                        drawable.setBounds(0, 0, width, height);
                        drawable.draw(canvas);
                        return bitmap;
                    }

                    @Override
                    public String key() {
                        return "rounded";
                    }
                }).into(ivImg);
        break;
    case R.id.btn_load_cancel:
        Picasso.with(PicassoActivity.this).cancelRequest(ivImg);
        break;
    }
}