Example usage for android.graphics.drawable BitmapDrawable BitmapDrawable

List of usage examples for android.graphics.drawable BitmapDrawable BitmapDrawable

Introduction

In this page you can find the example usage for android.graphics.drawable BitmapDrawable BitmapDrawable.

Prototype

private BitmapDrawable(BitmapState state, Resources res) 

Source Link

Usage

From source file:Main.java

public static Drawable getAsssetDrawableByName(Context context, String name) {
    try {//from   w w  w  .ja v a  2s  .c  o  m
        InputStream is = context.getAssets().open(name);
        return new BitmapDrawable(context.getResources(), BitmapFactory.decodeStream(is));
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new ColorDrawable(Color.TRANSPARENT);
}

From source file:Main.java

public static BitmapDrawable createDrawableFromView(Context context, View v) {
    Bitmap b = Bitmap.createBitmap(v.getLayoutParams().width, v.getLayoutParams().height,
            Bitmap.Config.ARGB_8888);/*from   w ww.  j av a2  s.  c o m*/
    Canvas c = new Canvas(b);
    v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
    v.draw(c);
    return new BitmapDrawable(context.getResources(), b);
}

From source file:Main.java

public static void background(@NonNull View v, Bitmap b) {
    background(v, new BitmapDrawable(v.getResources(), b));
}

From source file:Main.java

@SuppressWarnings("ResourceType")
public static TransitionDrawable bitmap2TransitionDrawable(Bitmap bitmap) {
    TransitionDrawable mBitmapDrawable = null;
    try {/*from ww w.ja v  a 2 s .c o m*/
        if (bitmap == null) {
            return null;
        }
        mBitmapDrawable = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(null, bitmap) });
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mBitmapDrawable;
}

From source file:Main.java

public static Drawable getDrawableFromFile(Context context, File pngFile, int density) {
    Bitmap bmp = BitmapFactory.decodeFile(pngFile.getPath());
    if (bmp != null)
        bmp.setDensity(density);//from  w  w  w .  j  ava  2 s  .  c  om

    return new BitmapDrawable(context.getResources(), bmp);
}

From source file:Main.java

/**
 * Decode byte array to drawable object/*from  www.  j av a 2s  .c  o m*/
 *
 * @param context Context to obtain {@link android.content.res.Resources}
 * @param array   The source byte array
 * @return The drawable created from source byte array
 */
public static Drawable getDrawableFromByteArray(Context context, byte[] array) {
    if (array == null) {
        return null;
    }
    Bitmap compass = BitmapFactory.decodeByteArray(array, 0, array.length);
    return new BitmapDrawable(context.getResources(), compass);
}

From source file:Main.java

public static BitmapDrawable getBitmapDrawableRes(Context context, int resId) {
    BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inPreferredConfig = Bitmap.Config.RGB_565;
    opt.inPurgeable = true;//from w w w  .j a  v a 2  s  .  c  o m
    opt.inInputShareable = true;
    InputStream is = context.getResources().openRawResource(resId);
    Bitmap bitmap = BitmapFactory.decodeStream(is, null, opt);
    try {
        is.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new BitmapDrawable(context.getResources(), bitmap);
}

From source file:Main.java

public static Drawable zoomDrawable(Drawable drawable, int w, int h) {
    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    Bitmap oldbmp = drawableToBitmap(drawable);
    Matrix matrix = new Matrix();
    float scaleWidth = ((float) w / width);
    float scaleHeight = ((float) h / height);
    matrix.postScale(scaleWidth, scaleHeight);
    Bitmap newbmp = Bitmap.createBitmap(oldbmp, 0, 0, width, height, matrix, true);
    return new BitmapDrawable(null, newbmp);
}

From source file:Main.java

public static BitmapDrawable createBitmapDrawableFrom(Resources res, Drawable drawable) {
    return new BitmapDrawable(res, createBitmapFrom(drawable));
}

From source file:Main.java

public static Drawable getDrawableImage(Context context, Bitmap source, int row, int col, int rowTotal,
        int colTotal, float multiple) {

    Bitmap temp = getBitmap(source, (col - 1) * source.getWidth() / colTotal,
            (row - 1) * source.getHeight() / rowTotal, source.getWidth() / colTotal,
            source.getHeight() / rowTotal);
    if (multiple != 1.0) {
        Matrix matrix = new Matrix();
        matrix.postScale(multiple, multiple);
        temp = Bitmap.createBitmap(temp, 0, 0, temp.getWidth(), temp.getHeight(), matrix, true);
    }//from  ww w. j av  a2  s .com
    Drawable d = new BitmapDrawable(context.getResources(), temp);
    return d;
}