如何在没有用户界面的情况下在 android 应用程序中拍照..? [英] How to take pictures in android application without the user Interface..?
本文介绍了如何在没有用户界面的情况下在 android 应用程序中拍照..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须设计一个应用程序,该应用程序必须从相机拍摄照片,而不在布局中显示它,也没有任何用户界面(如单击按钮......)并存储图片?
I have to design an application, that application has to take the picture from the camera without displaying it in the layout and without any user Interface (like click of a button....) and store the picture?
推荐答案
Camera mCamera;
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) {
mCamera.release();
mCamera = null;
}
}
//somewhere in your code call this:
mCamera.takePicture(null, null, mCall);
Camera.PictureCallback mCall = new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
//decode the data obtained by the camera into a Bitmap
FileOutputStream outStream = null;
try {
outStream = new FileOutputStream("/sdcard/Image.jpg");
outStream.write(data);
outStream.close();
} catch (FileNotFoundException e){
Log.d("CAMERA", e.getMessage());
} catch (IOException e){
Log.d("CAMERA", e.getMessage());
}
}
};
这篇关于如何在没有用户界面的情况下在 android 应用程序中拍照..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文