This article illustrates the solution to the black screen of the Android custom camera camera. Share to everyone for your reference, specific as follows:
For some phones, like HTC, when customizing camera, call Camera.parameters's parameters.setpreviewsize (width, height) method when the width and height are odd, There will be a black screen phenomenon, the solution can refer to the SDK provided by the Apidemos in the camera example:
List<size> sizes = parameters.getsupportedpreviewsizes ();
Size optimalsize = getoptimalpreviewsize (sizes, W, h);
Parameters.setpreviewsize (Optimalsize.width, optimalsize.height);
At the same time, setting the Parameters.setpicturesize (Width,height) attribute on the HTC phone also results in a black screen and no problem on the Samsung phone. And if you set the Setpreviewsize properties of the wide-height error, the photos will also be distorted and other bugs, so when the adaptation problem, the best way is not to set the Previewsize and Picturesize properties .
Getoptimalpreviewsize method
private Size getoptimalpreviewsize (list<size> sizes, int w, int h) {Final double
Aspect_tolerance = 0.05;
Double targetratio = (double) w/h;
if (sizes = null) return null;
Size optimalsize = null;
Double Mindiff = Double.max_value;
int targetheight = h; Try to find a size match aspect ratio and size for (size size:sizes) {Double ratio = (double) size.width/size.h
eight;
if (Math.Abs (ratio-targetratio) > Aspect_tolerance) continue;
if (Math.Abs (size.height-targetheight) < Mindiff) {optimalsize = size;
Mindiff = Math.Abs (size.height-targetheight); }//Cannot find the one match the aspect ratio, ignore the requirement if (optimalsize = null) {Mindiff = Double.
Max_value;
for (size size:sizes) {if (Math.Abs (size.height-targetheight) < Mindiff) {optimalsize = size;
Mindiff = Math.Abs (size.height-targetheight);
}} return optimalsize; }
For more information on Android-related content readers can view the site: "The Android photo and photo processing skills summary", "Android Development introduction and Advanced Course", "Android Multimedia operating skills Summary (audio, video, recording, etc.)", " Android Basic Components Usage Summary, Android View tips Summary, Android layout layout tips and Android Control usage summary
I hope this article will help you with the Android program.