android – Saving the byte array received from the camera directly to a file

Question:

I take a photo with a camera (not a third-party application). I want to save the image to disk. Is there a way to directly write byte [] to a file without intermediate conversion to bitmap?
now looks like this. it doesn't work very fast, as it seems to me, because of the conversion.

bitmap = BitmapFactory.decodeByteArray(source, 0, source.size())
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream)  

You won't be able to write byte [] directly into the stream (anticipating such responses), you need to support the jpeg format.

Answer:

If you don't need an intermediate bitmap at all, then get a photo from the camera directly as a file. With the help of a similar intent.

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), <имя файла>));
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
Scroll to Top