byte array to Drawable - Android File Input Output

Android examples for File Input Output:Byte Array Convert

Description

byte array to Drawable

Demo Code


//package com.java2s;
import android.graphics.Bitmap;

import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

public class Main {
    /**/*w  ww .  j a v  a2 s  .  com*/
     * @param byteArray
     * @return
     * @notice byte[]?Drawable
     */
    public static Drawable byte2Drawable(byte[] byteArray) {
        Bitmap bitmap = byte2Bitmap(byteArray);
        return bitmap2Drawable(bitmap);
    }

    /**
     * @param byteArray
     * @return
     * @notice byte[]?Bitmap
     */
    public static Bitmap byte2Bitmap(byte[] byteArray) {
        if (byteArray.length != 0) {
            return BitmapFactory.decodeByteArray(byteArray, 0,
                    byteArray.length);
        }
        return null;
    }

    public static Drawable bitmap2Drawable(Bitmap bitmap) {
        return bitmap == null ? null : new BitmapDrawable(bitmap);
    }
}

Related Tutorials