Android Bitmap to Byte Array Convert bmpToByteArray(final Bitmap bmp, final boolean needRecycle)

Here you can find the source of bmpToByteArray(final Bitmap bmp, final boolean needRecycle)

Description

bmp To Byte Array

Declaration

public static byte[] bmpToByteArray(final Bitmap bmp,
            final boolean needRecycle) 

Method Source Code

//package com.java2s;
import java.io.ByteArrayOutputStream;

import android.graphics.Bitmap;

import android.graphics.Bitmap.CompressFormat;

public class Main {
    public static byte[] bmpToByteArray(final Bitmap bmp,
            final boolean needRecycle) {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        bmp.compress(CompressFormat.PNG, 100, output);
        if (needRecycle) {
            bmp.recycle();/*from  w w  w  . j av  a2s.  com*/
        }

        byte[] result = output.toByteArray();
        try {
            output.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }
}

Related

  1. getBitmapData(Bitmap bmp)
  2. bitmapTobyte(Bitmap bmp)
  3. Bitmap2Bytes(Bitmap bm)
  4. bitmap2Bytes(Bitmap bitmap, Bitmap.CompressFormat mCompressFormat, final boolean needRecycle)
  5. bitmap2Bytes(Bitmap bm, Bitmap.CompressFormat format)
  6. convertBitmapToByteArray(Bitmap bitmap)
  7. bitmap2byte(Bitmap bitmap)
  8. putImagePath(String imagePath)
  9. getByteArrayFromImageUri(Activity ctx, Uri uri)