get BitmapDrawable - Android Graphics

Android examples for Graphics:Drawable

Description

get BitmapDrawable

Demo Code


//package com.java2s;

import android.content.res.Resources;
import android.graphics.Bitmap;

import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;

public class Main {
    /**/*  w  w  w  .  ja  v a 2  s.c o m*/
     * @param res
     * @param bitmap
     * @param bounds
     * @return
     */
    public static BitmapDrawable getBitmapDrawable(Resources res,
            Bitmap bitmap, Rect bounds) {
        BitmapDrawable bitmapDrawable = new BitmapDrawable(res, bitmap);
        if (bounds != null)
            bitmapDrawable.setBounds(bounds);
        else if (bitmap != null)
            bitmapDrawable.setBounds(0, 0, bitmap.getWidth(),
                    bitmap.getHeight());
        return bitmapDrawable;
    }

    /**
     * @param bitmap
     * @return
     */
    public static BitmapDrawable getBitmapDrawable(Bitmap bitmap) {
        return getBitmapDrawable(null, bitmap, null);
    }
}

Related Tutorials