Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.38 KB | None | 0 0
  1. public class CameraManager implements PictureCallback {
  2. private final static String DEBUG_TAG = "CameraManager";
  3.  
  4. public void TakePicture() {
  5. try {
  6. _camera = Camera.open(cameraId);
  7. Log.d(DEBUG_TAG, "Camera.TakePicture.open");
  8. SurfaceView view = new SurfaceView(CameraManager.this.getContext());
  9. _camera.setPreviewDisplay(view.getHolder());
  10. Log.d(DEBUG_TAG, "Camera.TakePicture.setPreviewDisplay");
  11. _camera.startPreview();
  12. Log.d(DEBUG_TAG, "Camera.TakePicture.startPreview");
  13.  
  14. AudioManager manager = (AudioManager) CameraManager.super.getContext().getSystemService(Context.AUDIO_SERVICE);
  15. Log.d(DEBUG_TAG, "Camera.TakePicture.AudioManager.ctor()");
  16. manager.setStreamVolume(AudioManager.STREAM_SYSTEM, 0 , AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
  17. Log.d(DEBUG_TAG, "Camera.TakePicture.setStreamVolume");
  18.  
  19. Camera.ShutterCallback shutter = new Camera.ShutterCallback() {
  20. @Override
  21. public void onShutter() {
  22. AudioManager manager = (AudioManager) CameraManager.super.getContext().getSystemService(Context.AUDIO_SERVICE);
  23. Log.d(DEBUG_TAG, "Camera.TakePicture.Shutter.AudioManager.ctor()");
  24. manager.setStreamVolume(AudioManager.STREAM_SYSTEM, manager.getStreamMaxVolume(AudioManager.STREAM_SYSTEM) , AudioManager.FLAG_ALLOW_RINGER_MODES);
  25. Log.d(DEBUG_TAG, "Camera.TakePicture.Shutter.setStreamVolume");
  26. }
  27. };
  28.  
  29. Camera.PictureCallback rawCallback = new Camera.PictureCallback() {
  30. @Override
  31. public void onPictureTaken(byte[] data, Camera camera) {
  32. if (data != null) {
  33. Log.i(DEBUG_TAG, "Picture taken::RAW");
  34. _camera.stopPreview();
  35. _camera.release();
  36. } else {
  37. Log.wtf(DEBUG_TAG, "Picture NOT taken::RAW");
  38. }
  39. }
  40. };
  41. _camera.takePicture(shutter, rawCallback, CameraManager.this);
  42. Log.d(DEBUG_TAG, "Camera.TakePicture.taken");
  43. } catch (Exception err) {
  44. err.printStackTrace();
  45. Log.d(DEBUG_TAG, "Camera.TakePicture.Exception:: %s" + err.getMessage());
  46. }
  47. }
  48.  
  49.  
  50. @Override
  51. public void onPictureTaken(byte[] data, Camera camera) {
  52. if (data != null) {
  53. Log.i(DEBUG_TAG, "Picture taken::JPG");
  54. _camera.stopPreview();
  55. _camera.release();
  56. } else {
  57. Log.wtf(DEBUG_TAG, "Picture NOT taken::JPG");
  58. }
  59. }
  60. }
  61.  
  62. [ 10-16 01:39:18.711 3873:0xf21 D/CameraManager ]
  63. Camera.TakePicture.open
  64.  
  65. [ 10-16 01:39:18.891 3873:0xf21 D/CameraManager ]
  66. Camera.TakePicture.setFrontCamera
  67.  
  68. [ 10-16 01:39:18.901 3873:0xf21 D/CameraManager ]
  69. Camera.TakePicture.setPreviewDisplay
  70.  
  71. [ 10-16 01:39:18.901 3873:0xf21 D/CameraManager ]
  72. Camera.TakePicture.startPreview
  73.  
  74. [ 10-16 01:39:18.901 3873:0xf21 D/CameraManager ]
  75. Camera.TakePicture.AudioManager.ctor()
  76.  
  77. [ 10-16 01:39:19.001 3873:0xf21 D/CameraManager ]
  78. Camera.TakePicture.setStreamVolume
  79.  
  80. [ 10-16 01:39:19.041 3873:0xf21 D/CameraManager ]
  81. Camera.TakePicture.taken
  82.  
  83. Camera.Parameters parameters = camera.getParameters();
  84. parameters.set("camera-id", 2);
  85. // (800, 480) is also supported front camera preview size at Samsung Galaxy S.
  86. parameters.setPreviewSize(640, 480);
  87. camera.setParameters(parameters);
  88.  
  89. Adds a pre-allocated buffer to the raw image callback buffer queue.
  90. Applications can add one or more buffers to the queue. When a raw image
  91. frame arrives and there is still at least one available buffer, the
  92. buffer will be used to hold the raw image data and removed from the
  93. queue. Then raw image callback is invoked with the buffer. If a raw
  94. image frame arrives but there is no buffer left, the frame is
  95. discarded. Applications should add buffers back when they finish
  96. processing the data in them by calling this method again in order
  97. to avoid running out of raw image callback buffers.
  98.  
  99. The size of the buffer is determined by multiplying the raw image
  100. width, height, and bytes per pixel. The width and height can be
  101. read from {@link Camera.Parameters#getPictureSize()}. Bytes per pixel
  102. can be computed from
  103. {@link android.graphics.ImageFormat#getBitsPerPixel(int)} / 8,
  104. using the image format from {@link Camera.Parameters#getPreviewFormat()}.
  105.  
  106. This method is only necessary when the PictureCallbck for raw image
  107. is used while calling {@link #takePicture(Camera.ShutterCallback,
  108. Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
  109.  
  110. Please note that by calling this method, the mode for
  111. application-managed callback buffers is triggered. If this method has
  112. never been called, null will be returned by the raw image callback since
  113. there is no image callback buffer available. Furthermore, When a supplied
  114. buffer is too small to hold the raw image data, raw image callback will
  115. return null and the buffer will be removed from the buffer queue.
  116.  
  117. @param callbackBuffer the buffer to add to the raw image callback buffer
  118. queue. The size should be width * height * (bits per pixel) / 8. An
  119. null callbackBuffer will be ignored and won't be added to the queue.
  120.  
  121. @see #takePicture(Camera.ShutterCallback,
  122. Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)}.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement