Android Bitmap to Byte Array Convert getByteArrayFromImageUri(Activity ctx, Uri uri)

Here you can find the source of getByteArrayFromImageUri(Activity ctx, Uri uri)

Description

get Byte Array From Image Uri

Declaration

public static Bitmap getByteArrayFromImageUri(Activity ctx, Uri uri) 

Method Source Code

//package com.java2s;
import java.io.FileNotFoundException;
import java.io.InputStream;

import android.app.Activity;

import android.content.ContentResolver;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;

public class Main {
    public static Bitmap getByteArrayFromImageUri(Activity ctx, Uri uri) {
        Bitmap data = null;//from www  . jav  a 2  s . c  om
        try {
            ContentResolver cr = ctx.getContentResolver();
            InputStream inputStream = cr.openInputStream(uri);
            data = BitmapFactory.decodeStream(inputStream);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        return data;
    }
}

Related

  1. bitmap2Bytes(Bitmap bm, Bitmap.CompressFormat format)
  2. bmpToByteArray(final Bitmap bmp, final boolean needRecycle)
  3. convertBitmapToByteArray(Bitmap bitmap)
  4. bitmap2byte(Bitmap bitmap)
  5. putImagePath(String imagePath)
  6. bitmap2Bytes(Bitmap bitmap, Bitmap.CompressFormat mCompressFormat, final boolean needRecycle)
  7. bitmap2Bytes(Bitmap bm)
  8. bmpToByteArray(final Bitmap bmp, final boolean needRecycle)
  9. convertBitmapToByte(Bitmap shopbitmap)