Android Bitmap to Byte Array Convert putImagePath(String imagePath)

Here you can find the source of putImagePath(String imagePath)

Description

put Image Path

Declaration

public static byte[] putImagePath(String imagePath) 

Method Source Code

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

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;

public class Main {

    public static byte[] putImagePath(String imagePath) {
        byte[] imageByte = null;

        try {//from  w  w  w .ja  v a 2  s. c o m
            BufferedInputStream in = new BufferedInputStream(
                    new FileInputStream(imagePath));
            ByteArrayOutputStream out = new ByteArrayOutputStream(1024);

            byte[] temp = new byte[1024];
            int size = 0;

            while ((size = in.read(temp)) != -1) {
                out.write(temp, 0, size);
            }

            in.close();

            imageByte = out.toByteArray();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return imageByte;
    }
}

Related

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