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

@Deprecated
public BitmapDrawable(java.io.InputStream is) 

Source Link

Document

Create a drawable by decoding a bitmap from the given input stream.

Usage

From source file:Main.java

@SuppressWarnings("deprecation")
public static Drawable bitmap2Drawable(Bitmap bm) {
    if (bm == null) {
        return null;
    }/* ww w . j  av  a  2 s. c o m*/
    BitmapDrawable bd = new BitmapDrawable(bm);
    bd.setTargetDensity(bm.getDensity());
    return new BitmapDrawable(bm);
}

From source file:Main.java

public static Drawable getDrawable(byte[] imgByte) {
    Bitmap bitmap;//ww w.j a  va2 s.co  m
    if (imgByte != null) {

        bitmap = BitmapFactory.decodeByteArray(imgByte, 0, imgByte.length);
        Drawable drawable = new BitmapDrawable(bitmap);

        return drawable;
    }
    return null;
}

From source file:Main.java

/**
 * Method setBackgroundImage//w w w.ja  va 2  s . c  o m
 */
public static void setBackgroundImage(Context context, View view, int resId) {
    InputStream inStream = context.getApplicationContext().getResources().openRawResource(resId);
    BitmapDrawable drawable = new BitmapDrawable(inStream);
    view.setBackgroundDrawable(drawable);
}

From source file:Main.java

/**
 * convert bitmap to drawable/*from  w w w  .jav  a  2  s .co  m*/
 *
 * @param mContext
 * @param bitmap   for convert to drawable
 * @return drawable image
 */
public static Drawable bitmapToDrawable(Context mContext, Bitmap bitmap) {
    return new BitmapDrawable(bitmap);
}

From source file:Main.java

/**
 * Convert the Bitmap image to drawable/*from   www  .j a  v  a2  s .co  m*/
 * @param mContext
 * @param bitmap
 * @return drawable
 */
public static Drawable bitmapToDrawable(@SuppressWarnings("UnusedParameters") Context mContext, Bitmap bitmap) {
    return new BitmapDrawable(bitmap);
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static Drawable bytesToDrawable(byte[] bytes) {
    Drawable drawable = null;/*from   w  ww .  ja  va2s  .  c o  m*/
    int length = bytes.length;
    Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, length);
    drawable = new BitmapDrawable(bitmap);
    return drawable;
}

From source file:Main.java

/**
 * byte[] -> Drawable// w w  w.  j a  v  a2s. c  o m
 * 
 * @param bytes
 * @return
 */
public static BitmapDrawable byteToDrawable(byte[] bytes) {
    Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, null);
    BitmapDrawable bd = new BitmapDrawable(bitmap);
    bitmap.recycle();
    bitmap = null;
    return bd;
}

From source file:Main.java

public static Drawable bitmapToDrawable(Bitmap bm) {
    BitmapDrawable bd = new BitmapDrawable(bm);
    return bd;
}

From source file:Main.java

/**
 * //w  w w .  j  a v  a2s  .c  o m
 * @param imgURL
 * @return
 */
public static BitmapDrawable downloadBitmapDrawable(String imgURL) {
    BitmapDrawable icon = null;
    try {
        URL url = new URL(imgURL);
        HttpURLConnection hc = (HttpURLConnection) url.openConnection();
        icon = new BitmapDrawable(hc.getInputStream());
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return icon;
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static Drawable getDrawableFromFile(File pngFile, int density) {
    Bitmap bmp = BitmapFactory.decodeFile(pngFile.getPath());
    bmp.setDensity(density);/* w  w  w .j  a v a 2s .  c  o  m*/

    return new BitmapDrawable(bmp);
}