In the process of studying zxing, there is always a doubt in the head, the camera is not photographed, how it gets the image
Look at the camera source with this confusion
The camera source has such an interface:
Public InterfacePreviewcallback {/*** Called as Preview frames is displayed. This callback was invoked * on the event thread {@link#open (int)} was called from. * * <p>if using the {@linkANDROID.GRAPHICS.IMAGEFORMAT#YV12} format, * Refer to the equations in {@linkCamera.parameters#setpreviewformat} * For the arrangement of the pixel data in the preview callback * Buffers. * * @paramdata The contents of the preview frame in the format defined * by {@linkAndroid.graphics.ImageFormat}, which can be queried * with {@linkAndroid.hardware.camera.parameters#getpreviewformat ()}. * If {@linkandroid.hardware.camera.parameters#setpreviewformat (int)} * is never called, the default would be The ycbcr_420_sp * (NV21) format. * @paramCamera the camera service object. */ voidOnpreviewframe (byte[] data, camera camera); };
Called as preview frames is displayed. This callback are invoked on the event thread were open(int) called from.
One of these " open(int) " is critical.
Interface used to deliver copies of preview frames as they is displayed. See Also:setpreviewcallback (Camera.previewcallback) setoneshotpreviewcallback (camera.previewcallback) Setpreviewcallbackwithbuffer (Camera.previewcallback) Startpreview ()
Choose one of these to open:
/*** <p>installs A callback to being invoked for the next preview frame in * addition to displaying it on the Screen. After one invocation, the * callback is cleared. This method can be called any time, even if * preview is live. Any other preview callbacks is overridden.</p> * * <p>if you is using the preview data to create vid EO or still images, * strongly consider using {@linkAndroid.media.MediaActionSound} to * properly indicate image capture or recording start/stop to the USER.</P&G T * * @paramCB A callback object that receives a copy of the next preview frame, * or NULL to stop receiving callbacks. * @seeAndroid.media.MediaActionSound*/ Public Final voidSetoneshotpreviewcallback (Previewcallback cb) {Mpreviewcallback=CB; Moneshot=true; Mwithbuffer=false; if(CB! =NULL) {musingpreviewallocation=false; } sethaspreviewcallback (CB!=NULL,false); }
Single-trigger mode, the callback function is started as soon as the preview is OK
Onpreviewframe (Byte[] data, camera camera)
The current window class frame information is loaded into byte[] data, so that the program will be the preview window image data.
The other two are continuous trigger mode, close to the video stream mode, each frame will be returned to the array, the implementation of the camera program is definitely called this function.
How the Android camera gets to the image