1.华为荣耀4a测试,分辨率一直是160*120?
2.求助
代码如下:
SurfaceHolder holder;
Camera cam;
Camera.Parameters myParameters;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photo);
initView();
}
private void initView() {
//双缓冲view
SurfaceView sfv= (SurfaceView) findViewById(R.id.surfaceView);
ViewGroup.LayoutParams lp = sfv.getLayoutParams();
lp.width = 750;
lp.height =1200;
sfv.setLayoutParams(lp);
//帮助类对象
holder = sfv.getHolder();
//指定类型
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
//指定回调接口
holder.addCallback(new A());
}
private class A implements SurfaceHolder.Callback {
@Override
public void surfaceCreated(SurfaceHolder holder) {
cam = Camera.open(0);
try {
myParameters = cam.getParameters();
myParameters.setPreviewFpsRange(20, 40);
myParameters.setPictureFormat(ImageFormat.JPEG);
myParameters.set("jpeg-quality", 85);
// myParameters.setPictureSize(750, 1280);
cam.setPreviewDisplay(holder);
cam.setDisplayOrientation(90);
// cam.setParameters(myParameters);
cam.startPreview();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
}
public void take(View v){
//创建图片
cam.takePicture(null,null,new B());
}
private class B implements Camera.PictureCallback {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
try {
Bitmap a= BitmapFactory.decodeByteArray(data,0,data.length);
//当前时间的毫秒数
long time = System.currentTimeMillis();
String path="/sdcard/"+time+".jpg";
FileOutputStream out=new FileOutputStream(new File(path));
//压缩
a.compress(Bitmap.CompressFormat.JPEG,100,out);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
我是这样写的,不过照片的最大分辨率是在Android底层编写的,所以这里写的分辨率都是在最大分辨率范围内修改的。