BitmapFactory decodeByteArray - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for BitmapFactory decodeByteArray method.

This code example shows how to use the following methods:decodeByteArray
     * @param image 
     * @param sampleSize 
     * @return bitmap or null if read fails 
     */ 
    public static Bitmap getBitmap(final byte[] image, int sampleSize) {
        final Options options = new Options();
        options.inDither = false;
        options.inSampleSize = sampleSize;
        return BitmapFactory.decodeByteArray(image, 0, image.length, options);
    } 
 
    /** 
     * Get scale for image of size and max height/width 
     * 
     * @param size 
     * @param width 
     * @param height 
     * @return scale 
     */ 
    public static int getScale(Point size, int width, int height) {
7
CodeRank
This code example shows how to use the following methods:decodeByteArray
        return requestDecode(jc, bytes, 0, bytes.length, options);
    } 
 
    public static Bitmap requestDecode(JobContext jc, byte[] bytes, int offset,
            int length, Options options) {
        if (options == null) options = new Options();
        jc.setCancelListener(new DecodeCanceller(options));
        return ensureGLCompatibleBitmap( 
                BitmapFactory.decodeByteArray(bytes, offset, length, options));
    } 
 
    public static Bitmap requestDecode(JobContext jc, final String filePath,
            Options options, int targetSize) {
        FileInputStream fis = null;
        try { 
            fis = new FileInputStream(filePath);
            FileDescriptor fd = fis.getFD();
            return requestDecode(jc, fd, options, targetSize);
        } catch (Exception ex) {
            Log.w(TAG, ex);
7
CodeRank
This code example shows how to use the following methods:decodeByteArray
     * @return The initialized BitmapDrawable. 
     */ 
    public static BitmapDrawable byteArrayToDrawable(byte[] image, Options opts, Context context) {
        if (opts == null) {
            Log.v(TAG, "opts is null, initializing without scaling");
            opts = new Options();
            opts.inScaled = false;
        } 
        Bitmap bmp = BitmapFactory.decodeByteArray(image, 0, image.length, opts);
        // bmp.setDensity(DisplayMetrics.DENSITY_HIGH); 
        return new BitmapDrawable(context.getResources(), bmp);
    } 
 
    /** 
     * Converts a byte array into a Bitmap, using the provided options. 
     * 
     * @param image The byte array representing the image. 
     * @param opts  The decoding options to use, or null if you'd like to use predefined 
     *              options (scaling will be not active). 
     * 
6
CodeRank
This code example shows how to use the following methods:decodeByteArray
        return requestDecode(jc, bytes, 0, bytes.length, options);
    } 
 
    public static Bitmap requestDecode(JobContext jc, byte[] bytes, int offset,
            int length, Options options) {
        if (options == null) options = new Options();
        jc.setCancelListener(new DecodeCanceller(options));
        return ensureGLCompatibleBitmap( 
                BitmapFactory.decodeByteArray(bytes, offset, length, options));
    } 
 
    public static Bitmap requestDecode(JobContext jc, final String filePath,
            Options options, int targetSize) {
        FileInputStream fis = null;
        try { 
            fis = new FileInputStream(filePath);
            FileDescriptor fd = fis.getFD();
            return requestDecode(jc, fd, options, targetSize);
        } catch (Exception ex) {
            Log.w(TAG, ex);
5
CodeRank
This code example shows how to use the following methods:decodeByteArray
        return requestDecode(jc, bytes, 0, bytes.length, options);
    } 
 
    public static Bitmap requestDecode(JobContext jc, byte[] bytes, int offset,
            int length, Options options) {
        if (options == null) options = new Options();
        jc.setCancelListener(new DecodeCanceller(options));
        return ensureGLCompatibleBitmap( 
                BitmapFactory.decodeByteArray(bytes, offset, length, options));
    } 
 
    public static Bitmap requestDecode(JobContext jc, final String filePath,
            Options options, int targetSize) {
        FileInputStream fis = null;
        try { 
            fis = new FileInputStream(filePath);
            FileDescriptor fd = fis.getFD();
            return requestDecode(jc, fd, options, targetSize);
        } catch (Exception ex) {
            Log.w(TAG, ex);
5
CodeRank
This code example shows how to use the following methods:decodeByteArray
     * Note: The returned image may be resized down. However, both width and height must be 
     * larger than the <code>targetSize</code>. 
     */ 
    public static Bitmap requestDecodeIfBigEnough(JobContext jc, byte[] data,
            Options options, int targetSize) {
        if (options == null) options = new Options();
        jc.setCancelListener(new DecodeCanceller(options));
 
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeByteArray(data, 0, data.length, options);
        if (jc.isCancelled()) return null;
        if (options.outWidth < targetSize || options.outHeight < targetSize) {
            return null; 
        } 
        options.inSampleSize = BitmapUtils.computeSampleSizeLarger(
                options.outWidth, options.outHeight, targetSize);
        options.inJustDecodeBounds = false;
        return ensureGLCompatibleBitmap( 
                BitmapFactory.decodeByteArray(data, 0, data.length, options));
    } 

5
CodeRank
This code example shows how to use the following methods:decodeByteArray
        return requestDecode(jc, bytes, 0, bytes.length, options);
    } 
 
    public static Bitmap requestDecode(JobContext jc, byte[] bytes, int offset,
            int length, Options options) {
        if (options == null) options = new Options();
        jc.setCancelListener(new DecodeCanceller(options));
        return ensureGLCompatibleBitmap( 
                BitmapFactory.decodeByteArray(bytes, offset, length, options));
    } 
 
    public static Bitmap requestDecode(JobContext jc, final String filePath,
            Options options, int targetSize) {
        FileInputStream fis = null;
        try { 
            fis = new FileInputStream(filePath);
            FileDescriptor fd = fis.getFD();
            return requestDecode(jc, fd, options, targetSize);
        } catch (Exception ex) {
            Log.w(TAG, ex);
5
CodeRank
This code example shows how to use the following methods:decodeByteArray
     * @return The initialized BitmapDrawable. 
     */ 
    public static BitmapDrawable byteArrayToDrawable(byte[] image, Options opts, Context context) {
        if (opts == null) {
            Log.v(TAG, "opts is null, initializing without scaling");
            opts = new Options();
            opts.inScaled = false;
        } 
        Bitmap bmp = BitmapFactory.decodeByteArray(image, 0, image.length, opts);
        // bmp.setDensity(DisplayMetrics.DENSITY_HIGH); 
        return new BitmapDrawable(context.getResources(), bmp);
    } 
 
    /** 
     * Converts a byte array into a Bitmap, using the provided options. 
     * 
     * @param image The byte array representing the image. 
     * @param opts  The decoding options to use, or null if you'd like to use predefined 
     *              options (scaling will be not active). 
     * 
4
CodeRank
This code example shows how to use the following methods:decodeByteArray
     * @param image 
     * @param sampleSize 
     * @return bitmap or null if read fails 
     */ 
    public static Bitmap getBitmap(final byte[] image, int sampleSize) {
        final Options options = new Options();
        options.inDither = false;
        options.inSampleSize = sampleSize;
        return BitmapFactory.decodeByteArray(image, 0, image.length, options);
    } 
 
    /** 
     * Get scale for image of size and max height/width 
     * 
     * @param size 
     * @param width 
     * @param height 
     * @return scale 
     */ 
    public static int getScale(Point size, int width, int height) {
5
CodeRank
This code example shows how to use the following methods:decodeByteArray
		// 2,这里做了压缩处理.调用Bitmap.compress()方法,唯一的压缩方法 
		// 注意,存储的时候,也做了压缩处理,@see PictureUtil.storePicture(mBitmap, fName); 
		byte[] mdata = PictureUtil.Bitmap2Bytes(mBitmap);
 
		// 获取宽度缩放比例 
		BitmapFactory.Options mOptions = new Options();
		mOptions.inJustDecodeBounds = true;// 当inJustDecodeBounds设成true时,bitmap并不加载到内存
		int scale_ratio = (int) (width / (float) STANDARD_WIDTH);
		LmUtils.logi(TAG, "ratio is - " + scale_ratio);
		if (scale_ratio <= 0)
			scale_ratio = 1;
		mOptions.inSampleSize = scale_ratio;
		mOptions.inJustDecodeBounds = false;
 
		// 3,这里再通过decodeByteArray将之前的bytes转换成bitmap 
		mBitmap = BitmapFactory.decodeByteArray(mdata, 0, mdata.length,
				mOptions);
		if (mBitmap == null) {
			LmUtils.logi(TAG, "bm is null");
			return null; 
		} 
4
CodeRank

Related BitmapFactory decodeByteArray Questions & Answers:

decodeByteArray Method Overview
Decode an immutable bitmap from the specified byte array.
See Code Examples for other Android BitmapFactory Methods: