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

public static Bitmap readBitmap(byte[] bytes) {
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}

From source file:Main.java

public static Bitmap yuv2bitmap(byte[] data, int width, int height) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    YuvImage yuvImage = new YuvImage(data, ImageFormat.NV21, width, height, null);
    yuvImage.compressToJpeg(new android.graphics.Rect(0, 0, width, height), 100, out);
    byte[] imageBytes = out.toByteArray();
    Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);

    // rotate/*from   w  w w . ja va  2s.co m*/
    Matrix matrix = new Matrix();
    matrix.postRotate(90);
    Bitmap dst = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    return dst;
}

From source file:Main.java

/**
 * Decode byte array to drawable object/* w ww  . j ava2s  . co  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

/**
 * Decodes a Base64 string into a Bitmap. Used to decode Bitmaps encoded by
 * {@link encodeBitmapAsString(Bitmap)}.
 * @param encodedString the Base64 String to decode.
 * @return the Bitmap which was encoded by the String.
 *///from  w w w.j a  v a2 s .  com
public static Bitmap decodeBitmapFromString(String encodedString) {
    if (TextUtils.isEmpty(encodedString))
        return null;
    byte[] decoded = Base64.decode(encodedString, Base64.DEFAULT);
    return BitmapFactory.decodeByteArray(decoded, 0, decoded.length);
}

From source file:Main.java

public static Bitmap compressByLimit(Bitmap bitmap, int limitSize) {
    if (bitmap == null) {
        return null;
    }/*from   w  w  w. jav  a2  s .  c  om*/
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int options = 100;
    bitmap.compress(Bitmap.CompressFormat.JPEG, options, baos);
    while (baos.size() > limitSize && options > 0) {
        options--;
        baos.reset();
        bitmap.compress(Bitmap.CompressFormat.JPEG, options, baos);
    }
    byte[] compressedData = baos.toByteArray();
    return BitmapFactory.decodeByteArray(compressedData, 0, compressedData.length);
}

From source file:Main.java

public static Bitmap bytesToBitmap(byte[] bytes) {
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}

From source file:Main.java

public static Bitmap getBitmapFromBytes(byte[] b) {
    if (b.length != 0) {
        return BitmapFactory.decodeByteArray(b, 0, b.length);
    } else {/*from w w  w. ja va  2  s. c  o m*/
        return null;
    }
}

From source file:Main.java

public static Bitmap getBitmapFromByte(byte[] temp) {
    if (temp != null) {
        Bitmap bitmap = BitmapFactory.decodeByteArray(temp, 0, temp.length);
        return bitmap;
    } else {// w ww  .  j  av  a2 s.co  m
        return null;
    }
}

From source file:Main.java

public static Bitmap bytes2Bimap(byte[] bytes) {
    if (bytes.length != 0) {
        return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
    } else {/*  ww  w . j  av  a2 s .co m*/
        return null;
    }
}

From source file:Main.java

public static Bitmap bytes2Bimap(byte[] b) {
    Bitmap bitmap = null;//from   w  w  w . ja v a 2  s  . c om
    try {
        if (b.length != 0) {
            bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return bitmap;
}