Take a picture and get bytes without saving on disk - android

Is it possible to take a picture and get the image as byte array without saving it?
All I want is, take an in memory picture. I don't want to save it. Also i plan to use other camera activity to take the picture (i mean, i don't want to implement my own camera logic)
Please note, I know that I can take a picture, read bytes and delete it. But I am looking if I can avoid this saving and deleting part, instead directly get the image in an in memory byte array.

Is it possible to take a picture and get the image as byte array without saving it?
That is the behavior of the android.hardware.Camera API, the android.hardware.camera2 API, and third-party libraries that simplify those APIs (e.g., Fotoapparat, CameraKit-Android).
i plan to use other camera activity to take the picture
If by "other camera activity", you mean a third-party camera app (e.g., via ACTION_IMAGE_CAPTURE), that will be difficult and unreliable. At best, you could try to use a content Uri pointing to a ContentProvider that you write that only holds onto written streams in memory. I would expect you to run out of heap space. Plus, not all camera apps will support a content Uri for EXTRA_OUTPUT (though they should).

Related

CameraX: show captured image and apply effects

I am trying to create Android CameraX app where user can take a photo, apply some image processing effects and view the result, without a need to save it to disk. But for me, the most challenging part is to pass the image to another activity where it will be processed.
I could create an Intent and attach the image using PutExtra(). But it would take too much memory and slow down the UI, since intent extras are not recommended to exceed 1 Mbyte. For example, 8MP photo would consume 24 Mb uncompressed and about 1.3 Mb in JPEG format.
Share the image in public class properties - according to Android docs, it's not a reliable way to pass data directly between activities, because the system may create and destroy them at any time.
Okay, let's capture the image into a file to and open it in our second activity. Or just call a built-in camera app to do so. It wouldn't be a problem for couple of images. But if user wants to capture 20-30 of them and more, it will cram the media folder and wear down the device storage.
Which is the best practice to pass image data between activities?
Store the image in your local storage and pass the URI of it as intent between activities because the ram is more costly than storage. This is a way how WhatsApp has exposed its intent to pass the image.
Also regarding multiple captures, you can easily handle it through code in your app.
Helpful Link
I have found a quite simple way: if I don't need more than one instance of certain data, I can declare an application level object (right click in java folder - new - kotlin file - enter name and choose "object"). It is initialised on first access, and stores its properties throughout the application's life. It may also contain methods to read/write/process the data.
In onCaptureSuccess(img: ImageProxy) listener I obtain the image from ImageProxy (it's in JPEG format), decode it with BitmapFactory and assign the Bitmap to object field. In other activity, all to do is to read the Bitmap from the object.

Disabling Android Camera automatic thumbnail

I've seen that Android automatically generates a thumbnail when taking a photo, and saves it as an extra with the key "data". Is it possible to disable that action, as to save space in the device?
I've seen that Android automatically generates a thumbnail when taking a photo, and saves it as an extra with the key "data".
No, it does not. Camera apps may generate thumbnails and put them in a data extra in the Intent used with setResult(). Android, the operating system, does not.
Is it possible to disable that action, as to save space in the device?
I do not know what "space" you think you will "save". That thumbnail is held briefly in system RAM. It is not stored on disk.
If you are a programmer, and if you are writing an Android app, and if you are using an ACTION_IMAGE_CAPTURE Intent with startActivityForResult() to invoke a third-party camera app, then you can include EXTRA_OUTPUT to indicate where you want a full-sized image to be written. According to the ACTION_IMAGE_CAPTURE specification, the data extra is not needed in that case. Some camera apps will then skip that extra.
However, developers of third-party camera apps are welcome to do whatever they want. If they want to create the data extra on every ACTION_IMAGE_CAPTURE request, that is their decision to make, as they are the ones writing the camera apps.

Prevent ACTION_IMAGE_CAPTURE from saving a picture

I am using an ACTION_IMAGE_CAPTURE Intent to take photos, which I then manipulate.
I want to save only the final image. How can I prevent photos from being saved immediately after photo is taken?
Your best bet is to copy the image returned in the result Intent and then use a ContentResolver to delete the original image. The different OEMs, of course, have different camera implementations. The procedure I described has worked with all of them from my testing.
This is assuming that there's some reason that you can't just manipulate the original image and write over it.
If you use a third-party app to take the picture for you:
The third-party app has to save the picture, because otherwise it cannot get the picture to you
The third-party app can do whatever else it wants, because it was written by somebody else, and they can do what they want
If that is unacceptable, do not use third-party apps to take the picture for you.

Keep Camera from saving photo

I have an application that captures pictures by dispatching an intent. Upon return of control to the activity, I retrieve the intent, extract the data, transform it into a bitmap and use it in my application. Just some straight forward code.
The pictures taken are subject to some privacy obligations and my application takes care to delete all data. The problem is that all pictures taken by the Camera application seem to automatically be saves into internal storage. I was successful in deleting screenshots taken by the device and by clearing all thumbnails. What remains to be done is keep the Camera application from storing picture in the first place.
The problem as I see it is that I relinquish control to the application and, hence, cannot influence it in any way. I tried launching ACTION_IMAGE_CAPTURE_SECURE but that failed. I would much prefer the approach of keeping the application from storing the image to the approach of having to scan the internal storage location for images and delete them as I tried it and failed.
Note: I have assigned all the right permissions. Should you need code, I will be happy to post it but there is nothing that cannot be found already in other threads. If there is no solution to my preferred approach, how would I go about deleting all images located in the internal storage at DCIM\Camera? Thank you!
If you need to override that behavior, don't take the pictures via intent. Take them yourself, using the android.hardware.Camera API.

Android Original / Default Camera Parameters

I have an application where i make use of the Camera API to specify my own settings and do some frame processing.
I need my application to take photos with the same settings the Android original Camera app does, but apparently I have no way to extract the procedures and intents from it. I have taken a look at the original Android Camera app class file, but it was not helpful, since it makes use of native routines for the parameters part...
Is there any way that I can obtain the parameters used by the original camera App? And in which way does it save the images?
I know that i can write to a File stream as suggested in many posts, and i have done so, but how can i actually save the specific information the device puts in the files, such as information on the camera, density, and such ?
Thanks in advance

Categories

Resources