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