How the Android camera gets to the image

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.