Android Bitmap to Byte Array Convert convertBitmapToByteArray(Bitmap bitmap)

Here you can find the source of convertBitmapToByteArray(Bitmap bitmap)

Description

convert Bitmap To Byte Array

Declaration

public static byte[] convertBitmapToByteArray(Bitmap bitmap) 

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[] convertBitmapToByteArray(Bitmap bitmap) {
        if (bitmap == null) {
            return null;
        } else {/*  w w w . j a va2s .co m*/
            byte[] b = null;
            try {
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                bitmap.compress(CompressFormat.PNG, 0,
                        byteArrayOutputStream);
                b = byteArrayOutputStream.toByteArray();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return b;
        }
    }
}

Related

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