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 getBitmapFromBase64(String base64Str) {

    if (TextUtils.isEmpty(base64Str)) {
        return null;
    }// www .  j a  v a  2 s  . c  o m

    byte[] bytes = Base64.decode(base64Str, Base64.NO_WRAP);
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}

From source file:Main.java

/**
 * convert byte[] to bitmap//from w ww  . j  av  a2s. co  m
 * 
 * @param b
 * @return Bitmap
 */
public static Bitmap bytes2Bitmap(byte[] b) {
    if (b == null || b.length == 0) {
        return null;
    } else {
        return BitmapFactory.decodeByteArray(b, 0, b.length);
    }
}

From source file:Main.java

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

From source file:Main.java

public static Bitmap bitmapFromBase64(String base64Str) {
    if (TextUtils.isEmpty(base64Str)) {
        return null;
    } else {// w w w. j  av a  2  s.  c om
        byte[] bytes = Base64.decode(base64Str, Base64.NO_WRAP);
        return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
    }
}

From source file:Main.java

public static Bitmap getBitmapFromBase64(String string) {
    byte[] bitmapArray = null;
    try {/*from   ww  w.jav  a2  s . c o m*/
        bitmapArray = Base64.decode(string, Base64.DEFAULT);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
}

From source file:Main.java

private static Bitmap compassBitmap(Bitmap src, Bitmap.CompressFormat format, int quality) {

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    src.compress(format, quality, os);/*  w w  w.jav a 2  s .  c o  m*/

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

From source file:Main.java

/**
 * Generate a bitmap from a byte array//from  w  ww.j  a va 2  s .c  om
 * @param imageInBytes the image in a byte array
 * @return the image as a bitmap
 */
public static Bitmap saveImageFromBytes(byte[] imageInBytes) {
    if (imageInBytes == null) {
        return null;
    }
    return BitmapFactory.decodeByteArray(imageInBytes, 0, imageInBytes.length);
}

From source file:Main.java

public static Bitmap getBitmapFromBase64encodedImage(String base64EncodedImage) {
    byte[] byteArray = Base64.decode(base64EncodedImage, Base64.DEFAULT);
    Bitmap image = null;/*ww  w .  j a v  a2s.  co  m*/
    try {
        image = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return image;
}

From source file:Main.java

public static Drawable getIcon(Context context, byte[] rawData) {
    if (rawData == null) {
        return null;
    }/*w  w  w.  j av a  2 s. c  om*/
    Bitmap bmp = BitmapFactory.decodeByteArray(rawData, 0, rawData.length);
    return new BitmapDrawable(context.getResources(), bmp);
}

From source file:Main.java

public static Bitmap getAudioImage(String audioPath) {
    MediaMetadataRetriever mmr = new MediaMetadataRetriever();
    Bitmap bitmap = null;/*ww  w  . ja v  a2 s.  c om*/
    try {
        mmr.setDataSource(audioPath);
        byte[] bb = mmr.getEmbeddedPicture();
        bitmap = BitmapFactory.decodeByteArray(bb, 0, bb.length);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return bitmap;
}