While I agree with Ovidiu Latcu , you may run into memory problems.
It might be better to save the bitmap in a temporary location on the SD card. And then access it from there. (Writing and reading a bitmap image to a file).
Alternatively, if you want to go with putting an array of bytes as optional, first copy the bitmap to a different format, for example. Jpeg or similar, this will again reduce memory problems.
A simple 8M image is 32 MB (4 layers). And this exceeds the allowed memory usage on most (if not all) phones for the application.
Storing directly in the storage is how the built-in camera application works to avoid this problem.
Here is my code for this:
public void showCameraScreen(View view) { // BUILT IN CAMERA Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); camera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTempFile(this)) ); this.startActivityForResult(camera, 1); } private File getTempFile(Context context) { // it will return /sdcard/MyImage.tmp final File path = new File(Environment.getExternalStorageDirectory(), context.getPackageName()); if (!path.exists()) { path.mkdir(); } return new File(path, "MyImage.tmp"); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 1 && resultCode == RESULT_OK) { final File file = getTempFile(this); byte[] _data = new byte[(int) file.length()]; try { InputStream in = new FileInputStream(file); in.read(_data); in.close(); in = null; //DO WHAT YOU WANT WITH _data. The byte array of your image. } catch (Exception E) { } } }
Note. You will also need to write code on your requested intent, which is stored in the passed Uri. Here the built-in api camera does this.
Doomsknight
source share