Example usage for android.graphics BitmapFactory decodeByteArray

List of usage examples for android.graphics BitmapFactory decodeByteArray

Introduction

In this page you can find the example usage for android.graphics BitmapFactory decodeByteArray.

Prototype

public static Bitmap decodeByteArray(byte[] data, int offset, int length) 

Source Link

Document

Decode an immutable bitmap from the specified byte array.

Usage

From source file:Main.java

/**
 * Converts a byteArray to a Bitmap object
 * @param byteArray// w w  w. j ava 2 s .co m
 * @return Bitmap
 */
public static Bitmap byteArrayToBitmap(byte[] byteArray) {
    if (byteArray == null) {
        return null;
    } else {
        return BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
    }
}

From source file:Main.java

public static Bitmap fromBase64(String base64) {
    Bitmap bitmap = null;//  www. j  a v a2 s  .  com
    if (base64 != null) {
        byte[] bytes = Base64.decode(base64, Base64.DEFAULT);
        if (null != bytes) {
            bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
        }
    }
    return bitmap;
}

From source file:Main.java

public static Bitmap deserialize(String bitmapBase64) {
    byte[] byteArray = Base64.decode(bitmapBase64, BASE64_FLAGS);
    Bitmap poster = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
    return poster;
}

From source file:Main.java

public static Bitmap base64StringToBitmap(String str) {
    if (str == null) {
        return null;
    }/*  w  w  w .  ja  v  a2  s .c  o m*/
    byte[] bytes;
    bytes = Base64.decode(str, Base64.DEFAULT);
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static Drawable bytesToDrawable(byte[] bytes) {
    Drawable drawable = null;/*  ww w. j  av  a 2  s.  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

public static Bitmap getImage(String body) {
    int index = TAG_IMAGE.length();
    body = body.substring(index);//from   w  w w.  j  a  va  2  s . c o  m
    byte[] imageData = Base64.decode(body, Base64.DEFAULT);
    return BitmapFactory.decodeByteArray(imageData, 0, imageData.length);

}

From source file:Main.java

public static Bitmap codec(Bitmap src, Bitmap.CompressFormat format, int quality) {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    src.compress(format, quality, os);//from  w ww .jav a  2s.  co m
    byte[] array = os.toByteArray();
    return BitmapFactory.decodeByteArray(array, 0, array.length);
}

From source file:Main.java

/**
 * raw byteArray into Bitmap//  w  ww .  j a v a  2  s .  c o m
 *
 * @param image the byteArray
 * @return Bitmap
 */
public static Bitmap imgToBitmap(final byte[] image) {
    if (image == null)
        return null;

    return BitmapFactory.decodeByteArray(image, 0, image.length);
}

From source file:Main.java

public static Bitmap codec(Bitmap src, Bitmap.CompressFormat format, int quality) {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    src.compress(format, quality, os);/*from   w w  w .j  a  v  a  2  s  .c  o  m*/

    byte[] array = os.toByteArray();
    return BitmapFactory.decodeByteArray(array, 0, array.length);
}

From source file:Main.java

/**
 * decode from a base64 to a bitmap//from   ww  w .  ja  v  a2  s. c o m
 * 
 * @param base64
 * @return
 */
public static Bitmap decodeFromBase64(String base64) {
    byte[] bitmapArray = Base64.decode(base64, Base64.NO_WRAP | Base64.URL_SAFE);
    return BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
}