问题背景:
大家好,我在安卓机拍照的过程中发现,使用原生相机拍照时,屏幕显示的画面范围比最后生成的照片要小。
下面给出具体的情况,请大家帮忙分析:
拍照时屏幕显示的画面:
outStream = new FileOutputStream(path);
outStream.write(data);
outStream.close();
finish(); //finish current activity
} catch (FileNotFoundException e) {
Log.e("TAG", "File Note Found", e);
} catch (IOException e) {
Log.e("TAG", "IO Exception", e);
}
}
};
//handle button snap
private void takePicture() {
camera.takePicture(shutterCallback, rawCallback, jpegCallback);
}
//handle button auto focus
private void doAutoFocus(){
Camera.Parameters parameters = camera.getParameters();
if(parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)){
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
camera.autoFocus(new AutoFocusCallback(){
public void onAutoFocus(boolean success, Camera camera){
Log.i("TAG","AutoFocus:"+(success?"Succeeded":"Failed"));
}
});
}
}
}
android:layout_
android:layout_>
android:layout_alignParentTop="true"
android:id="@+id/linearLayout1"
android:layout_
android:layout_
android:orientation="horizontal" >
android:layout_below="@id/linearLayout1"
android:id="@+id/surfaceView"
android:layout_
android:layout_ />
之前遇到一个bug:
当我使用下面代码时:
public void surfaceDestroyed(SurfaceHolder holder) {会报 Method called after release()的bug
//camera.stopFaceDetection();
camera.stopPreview();
}
@Override
protected void onPause() {
super.onPause();
camera.release();
}
将代码改为下面所示则没有bug。可能是因为camera.release()的时间问题,若放在onPause()中,销毁之后还会用到camera。有时间可以仔细分析。
@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
// TODO Auto-generated method stub
camera.setPreviewCallback( null) ; //debug
camera.stopPreview();
camera.release();
camera= null;
}
@Override
protected void onPause() {
super.onPause();
//camera.release();
}