已解决,请参阅评论--- 我从来没有从Camera.takePicture()得到回调,我在logcat中看到了。 缺什么?如何制作takePicture()...拍照?! 这大部分都是直接来自Android开发者的相机指南。我想以编程方式拍摄照片而无需任何预览或用户操作。使用内置的相机应用程序工作正常。 SDK 16。
在清单中我确实添加了:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera"
android:required="true" />
代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bTake = (Button)findViewById(R.id.b_take);
boolean boo = safeCameraOpen(camId);
Camera.Parameters parameters = mCamera.getParameters();
mCamera.setParameters(parameters);
bTake.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mCamera.takePicture(shutter, null, null, picture);
Log.e(getString(R.string.app_name), "After takePicture");
}
});
}// END onCreate
/* Camera operations */
private ShutterCallback shutter = new ShutterCallback() {
@Override
public void onShutter() {
Log.e(getString(R.string.app_name), "onShutter");
}
};
private PictureCallback picture = new PictureCallback() {
@Override
public void onPictureTaken(byte[] arg0, Camera arg1) {
Log.e(getString(R.string.app_name), "onPicTaken");
}
};
/* Starting up and closing down*/
private boolean safeCameraOpen(int id) {
boolean qOpened = false;
try {
releaseCamera();
mCamera = Camera.open(id);
qOpened = (mCamera != null);
} catch (Exception e) {
Log.e(getString(R.string.app_name), "failed to open Camera");
e.printStackTrace();
}
return qOpened;
}
private void releaseCamera() {
if (mCamera != null) {
((Camera) mCamera).release();
mCamera = null;
Log.e(getString(R.string.app_name), "cam released");
}
}}
答案 0 :(得分:0)
尝试:
mCamera.takePicture(shutter, picture, picture);