What is the use of callbacks in takepicture() - android

I am new to android and camera,so not able to understand clearly.
Why is JPEGcallback and Raw Picture callback required in camera takePicture?And how these callBacks are handled?
Please help.Thanks

This is asyc callback to notify that image data is ready after picture is taken.
So i.e. if you want to store imagedata to jpeg, then use bitmapfactory etc to store in desire format.
similarly if you want to take another picture you should not until this app notify by callback.

Related

get data byte[] in real time using camera2 api

I am working on Camera2 api with real time Image processing, i get
found method
onCaptureProgressed(CameraCaptureSession, CaptureRequest, CaptureResult)
call on every capturing fram but i have no idea how to get byte[] or data from CaptureResult
You can't get image data from CaptureResult; it only provides image metadata.
Take a look at the Camera2Basic sample app, which captures JPEG images with an ImageReader. If you change the JPEG format to YUV, set the resolution to preview size, and set the ImageReader Surface as a target for the preview repeating request, you'll get an ImageReader.Image for every frame captured.

camera matrix original image

As I know, when you using camera it crops some part of image. I mean that the application cuts out that part of the photo that goes beyond the rectangle.
Is there any way to get the original image that is full-sized and received directly from the camera's matrix?
Root access on my device is available.
I did a small demo years ago:
https://sourceforge.net/p/javaocr/code/HEAD/tree/trunk/demos/camera-utils/src/main/java/net/sf/javaocr/demos/android/utils/camera/CameraManager.java#l8
Basic idea is to set up callback, then you raw image data is delivered via byte array ( getPreviewFrame() / onPreviewFrame ) - no root access is necessary.
Actually, this data comes as mmapped memory buffer directly from adress space of camera app - no root is necessary
As this byte array does not provide any meta information, you have to get all the params from camera object yourself

Video as a source for the canvas drawImage() method is supported on Android?

do you know if the video as a source for the canvas drawImage() method is supported on Android?
The goal is to display the video and to select one moment to take a picture of this moment in a frame (drawImage (video,0,0), return canvas)). Do you think it is doable?
Thanks!
There is an approach in Android that will return you a bitmap for a given point in a video, which may give you want you need (or needed as this is an old question!):
MediaMetadataRetriever (https://developer.android.com/reference/android/media/MediaMetadataRetriever.html#getFrameAtTime%28long,%20int%29)
getFrameAtTime
Added in API level 10
Bitmap getFrameAtTime (long timeUs,
int option)
Call this method after setDataSource(). This method finds a representative frame close to the given time position by considering the given option if possible, and returns it as a bitmap. This is useful for generating a thumbnail for an input data source or just obtain and display a frame at the given time position.

Android How to receive jpg from web Api Call and Display it in ImageView

I have a quick question how to receive a jpg image from a web api call.
String result = webApiManager.getBarcode(dataStorageManager.currentUser.CustomerID);
This method returns a jpg image but I am unsure how to handle it and display it in an ImageView. Furthermore, what data type is a jpg image and how do I convert it into an image that I can display using an ImageView. Can someone point me in the right direction on how to accomplish this. Thanks for your time.
Regards,
Ryan
instead of returning the image as a jpg...why not just return the URL to the image and then use AsyncTask in processing it...
It will be easier and faster that way... just my 2cents

Photos captured from Android camera are completely black

I make a camera and try to capture a picture. Since the original data is YUV, I turn it into RGB using function:
static public void decodeYUV420SP(byte[] rgbBuf, byte[] yuv420sp,int width, int height)
However, the photo saved is completely black, there is no content in it.
I also found the following way:
mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
but the project was shut down.
Are there any other effective ways to save a photo? Thank you!
An old post, but it speaks of a similar problem that I have so I might as well answer the part I know :)
You're probably doing it wrong. I suggest you use the JPEG callback to store the image:
mCamera.takePicture(null, null, callbackJPEG);
This way you will get JPEG data into the routine which you can store into a file unmodified:
final Camera.PictureCallback mCall = new Camera.PictureCallback()
{
#Override
public void onPictureTaken(byte[] data, Camera camera)
{
//Needs <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
File sdCard = Environment.getExternalStorageDirectory();
File file = new File(sdCard, "pic.jpg");
fil = new FileOutputStream(file);
fil.write(data);
fil.close();
}
}
As far as the black picture goes, I have found that placing a simple Thread.sleep(250) between camera.startPreview() and camera.takePicture() takes care of that particular problem on my Galaxy Nexus.
I have no idea why this delay is necessary. Even if I add camera.setOneShotPreviewCallback() and call camera.takePicture() from the callback, the image comes out black if I don't first delay...
Oh, and the delay is not just "some" delay. It has to be some pretty long value. For example, 250ms sometimes works, sometimes not on my phone.
The complete black photo is a result of immediate call to mCamera.takePicture() after calling mCamera.startPreview(). Android should be given appropriate time to process its autofocus activity before taking the actual picture. The blackness is result of erratic exposure caused due to interruption while the autofocus was happening.
I recommend calling mCamera.autoFocus() right after mCamera.startPreview().
The mCamera.takePicture() should be called in the callback function of the autofocus function call.
This flow ensures that the picture is taken after the autofocus is complete and removes blackness or exposure issues from the image taken.
The delay mentioned in Velis' answer works for some devices because those devices complete autofocus activity. Ensuring proper callback flow removes this arbitrary delay and would work on every device.
I solved this issue using following argument:
final CaptureRequest.Builder captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
When I was using TEMPLATE_STILL_CAPTURE instead of TEMPLATE_PREVIEW, which was capturing my image as full black image. This thing works in my case.

Categories

Resources