Android Bitmap to Byte Array Convert convertBitmapToByte(Bitmap shopbitmap)

Here you can find the source of convertBitmapToByte(Bitmap shopbitmap)

Description

convert Bitmap To Byte

Declaration

public static byte[] convertBitmapToByte(Bitmap shopbitmap) 

Method Source Code

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

import android.graphics.Bitmap;

import android.util.Log;

public class Main {
    public static byte[] convertBitmapToByte(Bitmap shopbitmap) {
        ByteArrayOutputStream stream;
        int quality = 105;
        int MAX_IMAGE_SIZE = 100 * 1024;
        do {//from w  w w  . jav a2 s . c  o  m
            quality -= 5;
            stream = new ByteArrayOutputStream();
            shopbitmap
                    .compress(Bitmap.CompressFormat.JPEG, quality, stream);
        } while (stream.toByteArray().length >= MAX_IMAGE_SIZE);
        return stream.toByteArray();
    }
}

Related

  1. putImagePath(String imagePath)
  2. getByteArrayFromImageUri(Activity ctx, Uri uri)
  3. bitmap2Bytes(Bitmap bitmap, Bitmap.CompressFormat mCompressFormat, final boolean needRecycle)
  4. bitmap2Bytes(Bitmap bm)
  5. bmpToByteArray(final Bitmap bmp, final boolean needRecycle)
  6. getBytes(Bitmap bm)
  7. getByteCount(Bitmap bitmap, Bitmap.CompressFormat mCompressFormat)