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

/**
 * Create bitmap from byte array// w  ww . j a v  a 2 s  .  co  m
 * @param byteArray Original byte array
 * @return New bitmap
 */
public static Bitmap createBitmapFromByteArray(byte[] byteArray) {
    return BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
}

From source file:Main.java

public static byte[] compressBitmap(byte[] data, float size) {
    Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
    if (bitmap == null || getSizeOfBitmap(bitmap) <= size) {
        return data;
    }//from ww  w .  ja  v  a2s . c  o  m
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    int quality = 100;
    while ((baos.toByteArray().length / 1024f) > size) {
        quality -= 5;
        baos.reset();
        if (quality <= 0) {
            break;
        }
        bitmap.compress(Bitmap.CompressFormat.JPEG, quality, baos);
    }
    byte[] byteData = baos.toByteArray();
    return byteData;
}

From source file:Main.java

/**
 * bytes -> bitmap/* w w  w  .  java  2  s  .  c  om*/
 * 
 * */
public static Bitmap bytes2Bitmap(byte[] bytes) {
    if (null == bytes || bytes.length == 0) {
        return null;
    }

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

From source file:Main.java

public static Bitmap base64ToBitmap(String base64Data) {
    byte[] bytes = Base64.decode(base64Data.replaceFirst("data:image/jpeg;base64,", "").trim(), Base64.DEFAULT);
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}

From source file:Main.java

public static Bitmap decodeByteArray(byte[] src, int offset, int len) {
    if (null == src || len <= 0 || offset < 0) {
        return null;
    }//  w w w. j  av  a2 s.  com

    return BitmapFactory.decodeByteArray(src, offset, len);
}

From source file:Main.java

public static Bitmap decodeImageBase64(String bitmapString) {
    byte[] bytes = Base64.decode(bitmapString.getBytes(), Base64.DEFAULT);
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}

From source file:Main.java

/**
 * convert byte array to Bitmap//from w w  w  . j a va 2s  . c o m
 *
 * @param b
 * @return
 */
public static Bitmap byteToBitmap(byte[] b) {
    return (b == null || b.length == 0) ? null : BitmapFactory.decodeByteArray(b, 0, b.length);
}

From source file:Main.java

public static @Nullable Bitmap fromByteArray(@Nullable byte[] bytes) {
    if (bytes == null)
        return null;
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}

From source file:Main.java

@SuppressWarnings("unused")
public static Bitmap getImage(byte[] image) {
    if (image == null || image.length == 0) {
        return null;
    }/*ww w  . j a  v a 2  s  .  co  m*/
    return BitmapFactory.decodeByteArray(image, 0, image.length);
}

From source file:Main.java

public static Drawable getDrawable(byte[] imgByte) {
    Bitmap bitmap;/*from ww  w.j  a  v  a2  s  .c  o  m*/
    if (imgByte != null) {

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

        return drawable;
    }
    return null;
}