androidcamera对焦
1. 濡备綍瀹炵幇android镓嬫満鎽勫儚澶寸殑镄勮嚜锷ㄥ圭剑
鍙傝冧笅闱㈡柟娉
镙规嵁鐜版湁镄勮祫鏂欐湁濡备笅鍑犵嶏细
1 鏋佺浜虹墿镄勫仛娉曪细 浣跨敤涓涓瀹氭椂鍣锛岃惧畾瀹氭椂镞堕棿锛岀劧钖庝笉闂存柇镄勫圭剑銆
2 鏋佸浜虹墿镄勫仛娉曪细 闾e氨鏄鍒╃敤椹卞姩灞傚疄鐜帮纴浣嗘槸杩欎釜涓鑸浜鸿缮鏄绠椾简钖
3 灏辨湰浜鸿繖镙风殑瑙傚疗绯荤粺镄勫师鐢熺浉链哄缑鐭ワ纴杩欎笢涓滀篃娌$敤瀹氭椂鍣ㄥ晩锛岃矊浼间篃涓嶅彲鑳藉嶆潅鍒板叏鐢ㄩ┍锷ㄦ潵瀹炵幇锛屽嵆浣垮簳灞傜敤镄勬槸C 瀹炵幇锛屼絾鏄鐞呜轰笂璁诧纴google镶瀹氢细鎻愪緵杩欎釜灏佽呭ソ涓滀笢銆备簬鏄鏋沧柇镄勫幓镆ラ槄 DOC 涓鐪嬶纴鍙戠幇鏋灭劧链夎繖涓涓滀笢 锛 浠g爜濡备笅
[java] view plain print?
<strong><span style="font-size:18px">public class MainActivity extends Activity {
private SurfaceView surfaceView;
private SurfaceHolder surfaceHolder;
private boolean flag = false;
private String fileUrl="";
Camera camera;
Camera.Parameters parameters;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
surfaceView = (SurfaceView) findViewById(R.id.surfaceView1);
Button button=(Button) findViewById(R.id.takepicture);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
surfaceHolder.setKeepScreenOn(true);
surfaceView.setFocusable(true);
surfaceView.setBackgroundColor(TRIM_MEMORY_BACKGROUND);
surfaceHolder.addCallback(new Callback() {
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera.stopPreview();
camera.release();
camera=null;
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
if(null==camera){
camera=Camera.open();
try {
camera.setPreviewDisplay(surfaceHolder);
initCamera();
camera.startPreview();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height){
//瀹炵幇镊锷ㄥ圭剑
camera.autoFocus(new AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
if(success){
initCamera();//瀹炵幇鐩告満镄勫弬鏁板埯濮嫔寲
camera.cancelAutoFocus();//鍙链夊姞涓娄简杩欎竴鍙ワ纴镓崭细镊锷ㄥ圭剑銆
}
}
});
}
});
}
//鐩告満鍙傛暟镄勫埯濮嫔寲璁剧疆
private void initCamera()
{
parameters=camera.getParameters();
parameters.setPictureFormat(PixelFormat.JPEG);
//parameters.setPictureSize(surfaceView.getWidth(), surfaceView.getHeight()); // 閮ㄥ垎瀹氩埗镓嬫満锛屾棤娉曟e父璇嗗埆璇ユ柟娉曘
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);//1杩炵画瀵圭剑
setDispaly(parameters,camera);
camera.setParameters(parameters);
camera.startPreview();
camera.cancelAutoFocus();// 2濡傛灉瑕佸疄鐜拌繛缁镄勮嚜锷ㄥ圭剑锛岃繖涓鍙ュ繀椤诲姞涓
}
//鎺у埗锲惧儚镄勬g‘鏄剧ず鏂瑰悜
private void setDispaly(Camera.Parameters parameters,Camera camera)
{
if (Integer.parseInt(Build.VERSION.SDK) >= 8){
setDisplayOrientation(camera,90);
}
else{
parameters.setRotation(90);
}
}
//瀹炵幇镄勫浘镀忕殑姝g‘鏄剧ず
private void setDisplayOrientation(Camera camera, int i) {
Method downPolymorphic;
try{
downPolymorphic=camera.getClass().getMethod("setDisplayOrientation", new Class[]{int.class});
if(downPolymorphic!=null) {
downPolymorphic.invoke(camera, new Object[]{i});
}
}
catch(Exception e){
Log.e("Came_e", "锲惧儚鍑洪敊");
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}</span></strong>
2. 安卓系统手机专业模式对焦有几种对焦方式有什么拍摄特点,适合拍什么画面
安卓系统手机专业模式有3种对焦方式。1全自动对如链焦其特点是对焦迅速,对焦准确性不高,适合拍突发事件抓拍。2半自动对焦皮缓,其特点人为确定对焦和测光点。适合拍风光,燃橡模人像。3手动对焦,其特点可突出主体,虚化背景,适会拍花卉,静物等。