How to take pictures in an Android application without a user interface ..?

I need to design an application, should this application take a picture from the camera without displaying it in the layout and without any user interface (for example, clicking a button ...) and save the image?

+6
source share
1 answer
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()); } } }; 
+3
source

Source: https://habr.com/ru/post/950273/


All Articles