Android 获取摄像头像素,个数

最近做图片的,既然是图片,肯定有从摄像头那儿拍过来的,那么,对于你的手机摄像头,你知道什么?像素?个数?今天的代码就解释怎么获取


//1.0先获得一共有多少个摄像头 // 2.0分别与back还有front对比 //住哟:ftont"2 //back 1 import android.app.Activity; import android.hardware.Camera; import android.os.Bundle; import android.widget.Toast; import java.util.ArrayList; import java.util.List; public class MainActivity extends Activity { int cameracount = 0; Camera.CameraInfo cameraInfo = null; Camera camera; Camera.Parameters parameters; Camera.Size size; int x; List list = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); camera = Camera.open(); cameraInfo = new Camera.CameraInfo(); cameracount = Camera.getNumberOfCameras(); Toast.makeText(getApplicationContext(), "你的手机一共有" + cameracount + "个摄像头", Toast.LENGTH_SHORT).show(); hascamera(); } private void hascamera() { for (int cameranum = 0; cameranum < cameracount; cameranum++) { Camera.getCameraInfo(cameranum, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { Toast.makeText(getApplicationContext(), "你的手机有前置", Toast.LENGTH_SHORT).show(); } else if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { Toast.makeText(getApplicationContext(), "有后", Toast.LENGTH_SHORT).show(); parameters = camera.getParameters(); list = parameters.getSupportedPictureSizes(); size = list.get(0); x=size.height*size.width; if (x>10000) x/=10000; Toast.makeText(getApplicationContext(), x+"w像素", Toast.LENGTH_SHORT).show(); } } } }


代码比较简单,是以前无聊写的,就这样咯

你可能感兴趣的:(android,Android)