Android Camera encounters a pit

Source: Internet
Author: User

Onpicturetaken () cannot be recalled after taking pictures

Xiaomi mobile phone 3 found that the normal operation of the program can not be normal callback, and click the photo button will stay in the last photo screen, and the log will not have any error messages. The discovery was caused by the setting of the Setpicturesize () when the camera was initialized.

It is strange that the system camera is all right and can use the maximum hardware resolution, but my code can only support up to 2688x1520 picturesize, otherwise you will not receive the Onpicturetaken callback.

Later found that my previewsize set the system to the highest resolution 3840x2160, and later changed the resolution to the system screen approximate resolution, picturesize can set the highest resolution.

The following code is given:

/** Preview Interface Resolution * /     Public Static void setpreviewsize(Camera.parameters parametes)        {list<camera.size> localsizes = parametes.getsupportedpreviewsizes (); Camera.size biggestsize =NULL; Camera.size fitsize =NULL;//Priority screen resolutionCamera.size targetsize =NULL;//No screen resolution to take a size similar to the screen resolution (large)Camera.size TARGETSIZ2 =NULL;//No screen resolution to take a size similar to the screen resolution (small)        if(Localsizes! =NULL) {intCamerasizelength = Localsizes.size (); for(intn =0; n < camerasizelength; n++) {Camera.size Size = Localsizes.get (n);if(Biggestsize = =NULL|| (Size.width >= biggestsize.width && size.height >= biggestsize.height))                {biggestsize = size; }if(Size.width = = Deviceutils.screenhpixels && Size.Height = = deviceutils.screenwpixels)                {fitsize = size; }Else if(size.width = = Deviceutils.screenhpixels | | size.height = = deviceutils.screenwpixels) {if(Targetsize = =NULL) {targetsize = size; }Else if(Size.width < Deviceutils.screenhpixels | | Size.Height < deviceutils.screenwpixels)                    {targetSiz2 = size; }                }            }if(Fitsize = =NULL) {fitsize = targetsize; }if(Fitsize = =NULL) {fitsize = TARGETSIZ2; }if(Fitsize = =NULL) {fitsize = biggestsize;        } parametes.setpreviewsize (Fitsize.width, fitsize.height); }    }/** output photo is the highest pixel * /     Public Static void setpicturesize(Camera.parameters parametes)        {list<camera.size> localsizes = parametes.getsupportedpicturesizes (); Camera.size biggestsize =NULL; Camera.size fitsize =NULL;//Priority Select the size of the preview interfaceCamera.size previewsize = Parametes.getpreviewsize ();floatPreviewsizescale =0;if(Previewsize! =NULL) {Previewsizescale = Previewsize.width/(float) Previewsize.height; }if(Localsizes! =NULL) {intCamerasizelength = Localsizes.size (); for(intn =0; n < camerasizelength; n++) {Camera.size Size = Localsizes.get (n);if(Biggestsize = =NULL) {biggestsize = size; }Else if(Size.width >= biggestsize.width && size.height >= biggestsize.height)                {biggestsize = size; }//Select the highest resolution compared to the preview interface                if(Previewsizescale >0&& size.width >= previewsize.width && size.height >= previewsize.height) {floatSizescale = Size.width/(float) Size.Height;if(Sizescale = = Previewsizescale) {if(Fitsize = =NULL) {fitsize = size; }Else if(Size.width >= fitsize.width && size.height >= fitsize.height)                        {fitsize = size; }                    }                }            }//If Fitsize is not selected, then the largest size is fitsize            if(Fitsize = =NULL) {fitsize = biggestsize;        } parametes.setpicturesize (Fitsize.width, fitsize.height); }    }

Android Camera encounters a pit

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.