{"id":30,"date":"2015-03-31T10:11:04","date_gmt":"2015-03-31T10:11:04","guid":{"rendered":"https:\/\/boochlin.com\/?p=30"},"modified":"2015-03-31T10:11:04","modified_gmt":"2015-03-31T10:11:04","slug":"android-camera-analyze-%e4%b8%89-how-to-create-camera-2","status":"publish","type":"post","link":"https:\/\/boochlin.com\/?p=30","title":{"rendered":"Android Camera analyze (\u4e09) &#8211; How to create Camera 2."},"content":{"rendered":"<h3>How to create a camera 2<\/h3>\n<p><iframe style=\"border: 1px solid #CCC; border-width: 1px; margin-bottom: 5px; max-width: 100%;\" src=\"\/\/www.slideshare.net\/slideshow\/embed_code\/46420733\" width=\"600\" height=\"500\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" allowfullscreen=\"allowfullscreen\"> <\/iframe><\/p>\n<div style=\"margin-bottom: 5px;\"><strong> <a title=\"How to create a camera2\" href=\"\/\/www.slideshare.net\/boochlin\/camera2-how-tocreate\" target=\"_blank\">How to create a camera2<\/a><\/strong><\/div>\n<p><!--more--><\/p>\n<p>&nbsp;<\/p>\n<h4>page2:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>How to create a camera 2.<\/strong><br \/>\n<span style=\"color: #0000ff;\">Step1:To enumerate, query, and open available camera devices, obtain a<\/span> <span style=\"color: #ff0000;\">CameraManager<\/span> <span style=\"color: #0000ff;\">instance.<\/span><br \/>\n\u5f9esystem\u53d6\u5f97cameraManager\u3002<\/p>\n<pre>\/\/ To get a list of available sizes of camera preview, we retrieve an instance of\r\n\/\/ StreamConfigurationMap from CameraCharacteristics\r\nCameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);\r\nStreamConfigurationMap map = characteristics\r\n                    .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);\r\n (Camera.Size) mPreviewSize = map.getOutputSizes(SurfaceTexture.class)[0];\r\n (SurfaceTexture) mTextureView.setAspectRatio(mPreviewSize.getWidth(), \r\n\/\/ We are opening the camera with a listener. When it is ready, onOpened of\r\n\/\/ (CameraDevice.StateListener)mStateListener is called.\r\nmanager.openCamera(cameraId, mStateListener, null);\r\n<\/pre>\n<h4>page3:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>Initialize CameraDevice:<\/strong><br \/>\n<span style=\"color: #0000ff;\">Step2:Individual CameraDevices provide a set of<\/span> <span style=\"color: #ff0000;\">static property information<\/span> <span style=\"color: #0000ff;\">that describes the hardware<\/span> <span style=\"color: #0000ff;\">device and the<\/span> <span style=\"color: #ff0000;\">available settings<\/span> <span style=\"color: #0000ff;\">and<\/span> <span style=\"color: #ff0000;\">output parameters<\/span> <span style=\"color: #0000ff;\">for the device.<\/span><br \/>\n\u6839\u64dasystem \u53d6\u5f97 CameraCharacteristics \u53bb\u6e96\u5099\u958b\u555fCameraDevice<\/p>\n<pre>CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);\r\nmanager.openCamera(cameraId, mStateListener, null);\r\n<\/pre>\n<h4>page4:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>CameraDevice.StateListener:<\/strong><br \/>\n<span style=\"color: #0000ff;\">A listener for notifications about the state of a camera device<\/span><br \/>\n\u7e3d\u662f\u8981\u53bb\u76e3\u807ddevice\u662f\u5426\u958b\u555f\uff0c\u95dc\u9589\uff0c\u786c\u9ad4\u932f\u8aa4\u7b49\u7b49<\/p>\n<h4>page5:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>CameraDevice:<\/strong><br \/>\nThe CameraDevice class is a <span style=\"color: #ff0000;\">representation of a single camera connected to an Android device<\/span>, allowing for fine-grain control of image capture and post-processing at high frame rates.<br \/>\nDevice is modeled as a pipeline<br \/>\n\u91cd\u8981\u7684\u4e3b\u63a7\u7aef\uff0c\u8ca0\u8cac\u63a5\u6536\u6240\u6709callback \u548c\u5c0ddevice\u7684\u63a7\u5236<br \/>\n\u662f\u4e00\u500bpipline\u7684\u6a21\u7d44\u3002\u7c21\u55ae\u4f86\u8aaa\u7684\u6d41\u7a0b<br \/>\nInput : <span style=\"color: #ff0000;\">CaptureRequest<\/span> for a <span style=\"color: #ff0000;\">single Frame<\/span><br \/>\nOutput: <span style=\"color: #ff0000;\">CaptureResult Metadata packet<\/span> + <span style=\"color: #ff0000;\">output image buffers<\/span> for the request. These buffers can go to one or <span style=\"color: #ff0000;\">multiple output targets.<\/span><\/p>\n<h4>page6:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>Start preview :<\/strong><br \/>\n<span style=\"color: #0000ff;\">Step3:To capture or stream images from a camera device, the application must first create a camera<\/span> <span style=\"color: #ff0000;\">capture session with a set of output Surfaces<\/span><span style=\"color: #0000ff;\"> for use with the camera device.<\/span><br \/>\n\u958b\u555f\u9810\u89bd\u756b\u9762\uff0c\u57fa\u672c\u4e0a\u53ef\u4ee5\u540c\u6642\u767c\u5230\u597d\u5e7e\u500bsurface<br \/>\n\u9019\u88e1\u4ee5\u55ae\u4e00surface\u70ba\u4e3b\uff0c\u9019\u88e1\u8981\u8a18\u5f97\u958b\u555fcapturesession\u662f\u5fc5\u9808\u5305\u542b\u672a\u4f86\u6700\u5927\u5b50\u96c6\u9700\u8981\u7528\u5230\u7684surface<\/p>\n<pre>\/\/ We configure the size of default buffer to be the size of camera preview we want.\r\ntexture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());\r\n\/\/ This is the output Surface we need to start preview.\r\nSurface surface = new Surface(texture);\r\n\/\/ We set up a CaptureRequest.Builder with the output Surface.\r\nmPreviewBuilder =  mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);\r\nmPreviewBuilder.addTarget(surface);\r\n\/\/ Here, we create a CameraCaptureSession for camera preview.\r\nmCameraDevice.createCaptureSession(Arrays.asList(surface),\r\n                    new CameraCaptureSession.StateListener(){.....}\r\n<\/pre>\n<h4>page7:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>CaptureRequest.Builder:<\/strong><br \/>\n&#8211; A builder for <span style=\"color: #ff0000;\">capture requests.<\/span><br \/>\n&#8211; To obtain a builder instance, use the <span style=\"color: #ff0000;\">createCaptureRequest(int)<\/span> method, which initializes the request fields to one of the templates defined in <span style=\"color: #ff0000;\">CameraDevice.<\/span><\/p>\n<p style=\"padding-left: 30px;\">\u6240\u6709\u7684request\u90fd\u5fc5\u9808\u7d93\u904e\u6307\u5b9a\u63d0\u4f9b\u7684builder\u7684\u63d0\u4f9b\uff0c\u9019\u5728\u4e0d\u5c11android\u7684\u8a2d\u8a08\u90fd\u662f\u9019\u6a23\u641e<br \/>\n\u50cf\u662fnotification\u3002<br \/>\n\u901a\u5e38\u8981\u5beb\u5165captureRequest\u7684field \u8a2d\u5b9a\u548c\u8f38\u51fa\u7684target surface.<\/p>\n<h4>page8:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>CaptureRequest:<\/strong><br \/>\n&#8211; An immutable package of <span style=\"color: #ff0000;\">settings<\/span> and<span style=\"color: #ff0000;\"> outputs<\/span> needed to capture a <span style=\"color: #ff0000;\">single image<\/span> from the camera device.<br \/>\n&#8211; Contains the <span style=\"color: #ff0000;\">configuration<\/span> for the capture hardware (sensor, lens, flash), the processing pipeline, the control algorithms, and the output buffers. Also <span style=\"color: #ff0000;\">contains the list of target Surfaces to send image data to for this capture.<\/span><br \/>\n&#8211; CaptureRequests can be created by using a <span style=\"color: #ff0000;\">CaptureRequest.Builder<\/span> instance, obtained by calling createCaptureRequest(int)<br \/>\n\u61f6\u5f97\u89e3\u91cb\u4e86\uff0c\u6839\u64da\u4e0a\u9801\uff0c\u505a\u51fa\u4f86\u7684request\u901a\u5e38\u6703\u6709\u5927\u91cf\u7684\u8cc7\u8a0a\uff0c\u4e00\u822c\u4f86\u8aaa1 request \u00a0\u5c0d\u61c91 image data<br \/>\n\u9019\u4e5f\u662fcamera2 \u7684\u91cd\u8981\u7279\u8272\uff0c\u5728request \u4e2d\u53ef\u4ee5\u653e\u5165\u5404\u7a2e\u8a2d\u5b9a\u548c\u8f38\u51fasurface\uff0c\u6240\u4ee5\u53ef\u4ee5\u540c\u6642\u6709\u5f88\u591a\u7a2e\u8b8a\u5316\u5728\u5f88\u77ed\u7684\u6642\u9593(fps)<\/p>\n<h4>page9:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>CameraCaptureSession.StateListener:<\/strong><br \/>\n<span style=\"color: #0000ff;\">A listener for tracking the state of a camera capture session.<\/span><br \/>\n\u9664\u4e86\u4e4b\u524d\u7684cameradevice\u76e3\u63a7\uff0c\u4e4b\u5916\u9084\u8981\u76e3\u63a7capturesession\u72c0\u6cc1<br \/>\n\u524d\u8ff0\u6709\u63d0\u904e\uff0c\u7576\u958b\u555fcameraDevice\u9084\u662f\u8981\u958b\u555f\u5c08\u9580\u7684session\u53bb\u57f7\u884c<br \/>\ncaptureSession\u7684\u8a73\u7d30\u5167\u5bb9\u53ef\u4ee5\u53c3\u8003\u4e0b\u4e00\u9801<\/p>\n<pre>public void onConfigured(CameraCaptureSession cameraCaptureSession) {\r\n             \/\/ When the session is ready, we start displaying the preview.\r\n             mPreviewSession = cameraCaptureSession;\r\n             \/\/ In this sample, we just let the camera device pick the automatic settings.\r\n\t\t     mPreviewBuilder.set(CaptureRequest.CONTROL_MODE\r\n\t\t\t\t, CameraMetadata.CONTROL_MODE_AUTO);\r\n             HandlerThread thread = new HandlerThread(\"CameraPreview\");\r\n            thread.start();\r\n            Handler backgroundHandler = new Handler(thread.getLooper());\r\n            \/\/ Finally, we start displaying the camera preview.\r\n            mPreviewSession.setRepeatingRequest(mPreviewBuilder.build(), null, backgroundHandler);\r\n       }\r\n<\/pre>\n<h4>page10:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>CameraCaptureSession:<\/strong><br \/>\n&#8211; A <span style=\"color: #0000ff;\">configured capture session for a CameraDevice<\/span>, used for <span style=\"color: #ff0000;\">capturing images from the camera.<\/span><br \/>\n&#8211; A CameraCaptureSession is created by providing a <span style=\"color: #ff0000;\">set of target output surfaces<\/span> to createCaptureSession. Once created, the session is <span style=\"color: #0000ff;\">active until a new session is created by the camera device, or the camera device is closed.<\/span><br \/>\nCaptureSession\u7684\u5e7e\u500bapi\u5f88\u660e\u986f\u5c31\u662f\u4f86\u89e3\u6c7a zero shutter lag\uff0c\u81ea\u5df1\u611f\u53d7\u611f\u53d7<\/p>\n<pre>capture(CaptureRequest request, CameraCaptureSession.CaptureListener listener, Handler handler)\r\nSubmit a request for an image to be captured by the camera device.\r\n\r\ncaptureBurst(List requests, CameraCaptureSession.CaptureListener listener, Handler handler)\r\nSubmit a list of requests to be captured in sequence as a burst.\r\n\r\nsetRepeatingBurst(List requests, CameraCaptureSession.CaptureListener listener, Handler handler)\r\nRequest endlessly repeating capture of a sequence of images by this capture session.\r\n\r\nsetRepeatingRequest(CaptureRequest request, CameraCaptureSession.CaptureListener listener, Handler handler)\r\nRequest endlessly repeating capture of images by this capture session.\r\n<\/pre>\n<p>\u4e0d\u5f97\u4e0d\u8aaa\u90a3\u500bburst\u6839\u672c\u5c31\u662fburst\uff0c\u81ea\u5df1\u5beb\u904e\u5e7e\u6b21\u5c31\u77e5\u9053\u5566\uff0c\u4e0d\u904e\u8981\u771f\u7684\u5feb\u7684\u8a71\u76ee\u524d\u53ea\u6709nexus 9 \u548c 6\u3002<\/p>\n<h4>page11:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>Take picture1:<\/strong><br \/>\n<span style=\"color: #0000ff;\">Step4: Capture of JPEG images or <span style=\"color: #ff0000;\">RAW buffers<\/span> for Dng Creator can be done with ImageReader with the {android.graphics.ImageFormat#JPEG} and {android.graphics.ImageFormat#RAW_SENSOR} formats.<\/span><\/p>\n<p style=\"padding-left: 30px;\">raw buffer \u00a0\u662fcamera2 \u624d\u652f\u63f4\uff5e\uff5e<\/p>\n<pre>CameraManager manager =\r\n            (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);\r\n\/\/ Pick the best JPEG size that can be captured with this CameraDevice.\r\nCameraCharacteristics characteristics =\r\nmanager.getCameraCharacteristics(mCameraDevice.getId());\r\nSize[] jpegSizes = null;\r\nif (characteristics != null) {\r\n           jpegSizes = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP) .getOutputSizes(ImageFormat.JPEG);\r\n   }\r\n int width = 640; int height = 480;\r\n if (jpegSizes != null &amp;&amp; 0 &lt; jpegSizes.length) {\r\n            width = jpegSizes[0].getWidth();\r\n             height = jpegSizes[0].getHeight();\r\n    }\r\n\r\n\/\/ This is the CaptureRequest.Builder that we use to take a picture.\r\nfinal CaptureRequest.Builder captureBuilder =\r\nmCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);\r\ncaptureBuilder.addTarget(reader.getSurface());\r\n\/\/ In this sample, we just let the camera device pick the automatic settings. captureBuilder.set(CaptureRequest.CONTROL_MODE,CameraMetadata.CONTROL_MODE_AUTO);\r\n\r\n<\/pre>\n<h4>page12:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>\u627f\u4e0a takePicture2<\/strong><br \/>\n<span style=\"color: #0000ff;\">Step5:Use ImageReader to get output data<\/span><\/p>\n<pre>\/\/ We use an ImageReader to get a JPEG from CameraDevice.\r\n\/\/ Here, we create a new ImageReader and prepare its Surface as an output from camera.\r\nImageReader reader = ImageReader.newInstance(width, height, ImageFormat.JPEG, 1);\r\nList outputSurfaces = new ArrayList(2);\r\noutputSurfaces.add(reader.getSurface());\r\noutputSurfaces.add(new Surface(mTextureView.getSurfaceTexture()));\r\n\r\n\/\/ This is the CaptureRequest.Builder that we use to take a picture.\r\nfinal CaptureRequest.Builder captureBuilder =\r\nmCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);\r\ncaptureBuilder.addTarget(reader.getSurface());\r\n\/\/ In this sample, we just let the camera device pick the automatic settings. captureBuilder.set(CaptureRequest.CONTROL_MODE,CameraMetadata.CONTROL_MODE_AUTO);\r\n\r\n<\/pre>\n<h4>page13:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>ImageReader:<\/strong><br \/>\nThe ImageReader class allows direct application access to<span style=\"color: #ff0000;\"> image data rendered into a Surface<\/span><br \/>\n\u70ba\u4e00\u7a2e\u66ab\u5b58\u7684 image data buffer consumer. \u6bd4\u8f03\u7279\u5225\u7684\u662f\u6709size\u53ef\u4ee5\u8a2d\u5b9a\uff0capi19\u524d\u5e7e\u4e4e\u6c92\u6709\u3002<\/p>\n<h4>page14:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>Take picture3<\/strong><br \/>\n<span style=\"color: #0000ff;\">Step6:Set output data parameters.<\/span><br \/>\n\u6b64\u968e\u6bb5\u540c\u6642\u8a2d\u5b9a image reader listener\uff0c\u7528\u4f86\u63a5\u6536device\u767c\u51fa\u7684\u8cc7\u6599\u3002<\/p>\n<pre>\/\/ In this sample, we just let the camera device pick the automatic settings.\r\ncapturebuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);\r\n\/\/ Orientation\r\nint rotation = activity.getWindowManager().getDefaultDisplay().getRotation();\r\ncaptureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));\r\n\/\/ Output file\r\nfinal File file = new File(activity.getExternalFilesDir(null), \"pic.jpg\");\r\n\/\/ This listener is called when a image is ready in ImageReader\r\nImageReader.OnImageAvailableListener readerListener =\r\nnew ImageReader.OnImageAvailableListener() {\u2026.}\r\n<\/pre>\n<h4>page15:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>ImageReader.OnImageAvailableListener<\/strong><br \/>\n<span style=\"color: #0000ff;\">Callback interface for being notified that a new image is available.<\/span><\/p>\n<pre>onImageAvailable(ImageReader reader) {\u00a0\r\nimage = reader.acquireLatestImage();\r\nByteBuffer buffer = image.getPlanes()[0].getBuffer();\r\nbyte[] bytes = new byte[buffer.capacity()];\r\nbuffer.get(bytes);\r\nsave(bytes);\r\n\u2026..\/\/Use output stream to write out to file.\r\n\u2026\u2026\r\nImage.close();\r\n<\/pre>\n<h4>page16:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>Take picture4<\/strong><br \/>\n<span style=\"color: #0000ff;\">Step7:Set output data parameters. And start camera capture picture thread.\u00a0<\/span><\/p>\n<pre>\/\/ In this sample, we just let the camera device pick the automatic settings.\r\ncapturebuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);\r\n\/\/ Orientation\r\nint rotation = activity.getWindowManager().getDefaultDisplay().getRotation();\r\ncaptureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));\r\n\/\/ Output file\r\nfinal File file = new File(activity.getExternalFilesDir(null), \"pic.jpg\");\r\n\/\/ This listener is called when a image is ready in ImageReader\r\n ImageReader.OnImageAvailableListener readerListener =\r\n               new ImageReader.OnImageAvailableListener() {\u2026.}\r\n\/\/ We create a Handler since we want to handle the result JPEG in a background thread\r\nHandlerThread thread = new HandlerThread(\"CameraPicture\");\r\nthread.start();\r\nfinal Handler backgroundHandler = new Handler(thread.getLooper());\r\nreader.setOnImageAvailableListener(readerListener, backgroundHandler);\r\n\r\n<\/pre>\n<h4>page17:<\/h4>\n<p style=\"padding-left: 30px;\"><strong>takePicture5<\/strong><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"color: #0000ff;\">Step8:Restart preview thread after capture complete.<\/span><br \/>\n\u9019\u88e1\u662f\u6709\u9806\u5e8f\u7684\uff0c\u518dcapturesession listener \u7684 capture complete \u5f8c\u91cd\u8d77startpreview()<br \/>\n\u5148\u8aaa\u9019\u500bstartpreview()\u4e0d\u662fcamera1\u7684api \uff0c\u800c\u662f\u4e4b\u524d\u6211\u5011\u81ea\u5df1\u5beb\u7684 startpreview()<br \/>\n\u4ee5\u767c\u751f\u6642\u9593\u4f86\u6392\u5e8f\u662f\u53f3\u908a\u5148 \u5de6\u908a\u5f8c<\/p>\n<pre>\/\/ Finally, we can start a new CameraCaptureSession to take a picture. mCameraDevice.createCaptureSession(outputSurfaces,\r\nnew CameraCaptureSession.StateListener() {\r\npublic void onConfigured(CameraCaptureSession session) {\r\n\ttry {\r\n\t\tsession.capture(captureBuilder.build(), captureListener,\r\n                                        backgroundHandler);\r\n\t} catch (CameraAccessException e) {\r\n\t\te.printStackTrace();\r\n\t}\r\n     }\r\n}, backgroundHandler );     \r\n<\/pre>\n<p>then<\/p>\n<pre>\/\/ This listener is called when the capture is completed.\r\n\/\/ Note that the JPEG data is not available in this listener, but in the\r\n \/\/ ImageReader.OnImageAvailableListener we created above.\r\n final CameraCaptureSession.CaptureListener captureListener =\r\n\tnew CameraCaptureSession.CaptureListener() {\r\n\tpublic void onCaptureCompleted(CameraCaptureSession session,\r\n\tCaptureRequest request,   TotalCaptureResult result) {\r\n          \/\/ We restart the preview when the capture is completed\r\n                            startPreview();\r\n\t\t\t}\r\n\t\t};\r\n<\/pre>\n<p><span style=\"color: #ff0000;\">\u4ee5\u4e0a\u662fCamera2\u7684takePicture\u7c21\u6613\u5be6\u4f5c\u904e\u7a0b\uff0c\u6700\u91cd\u8981\u7684\u9084\u662f\u627e\u5230\u4e00\u53f0\u53ef\u4ee5\u8dd1hal3\u7684\u6a5f\u5668<\/span><br \/>\n<span style=\"color: #ff0000;\"> \u4e0d\u7136\u5f88\u591a\u529f\u80fd\u90fd\u662f\u95dc\u6389\u7684\uff0c\u7d50\u679c\u5c31\u6703\u50cf\u662f\u53ea\u662f\u63db\u500b\u5beb\u6cd5\u5bebcamera1<\/span><br \/>\n\u5b8c\u6574\u7a0b\u5f0f\u78bc<br \/>\n<a title=\"https:\/\/github.com\/googlesamples\/android-Camera2Basic\" href=\"https:\/\/github.com\/googlesamples\/android-Camera2Basic\">https:\/\/github.com\/googlesamples\/android-Camera2Basic<\/a><br \/>\ngoogle i\/o \u4ecb\u7d39<br \/>\n<a title=\"https:\/\/www.google.com\/events\/io\" href=\"https:\/\/www.google.com\/events\/io\">https:\/\/www.google.com\/events\/io<\/a><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u53ef\u80fd\u770b\u6295\u5f71\u7247\u6216\u662f\u958b\u767c\u6642\u60f3\u4e0d\u900f\u7684\u90e8\u4efd\u505a\u6210QA<\/p>\n<h4><strong>Q1:synchronize?<\/strong><\/h4>\n<p>A1:\u65b0\u7684capture request \u540c\u6642\u5305\u542bparameter\u7684setting\u548ccapture \u7684\u884c\u70ba\uff0c\u4e26\u57f7\u884c\u65bccamera device\u7aef\uff0c\u904e\u53bbold camera \u5247\u662f\u5c07\u9019\u5169\u500b\u884c\u70ba\u5206\u958b\u4e26\u7531ap\u7aef\u53bbcontrol\u3002<br \/>\n<a href=\"https:\/\/boochlin.com\/wp-content\/uploads\/2015\/03\/syn.jpg\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-35\" src=\"https:\/\/boochlin.com\/wp-content\/uploads\/2015\/03\/syn.jpg\" alt=\"syn\" width=\"1280\" height=\"720\" \/><\/a><\/p>\n<h4><\/h4>\n<p><a href=\"https:\/\/boochlin.com\/wp-content\/uploads\/2015\/03\/system.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-36\" src=\"https:\/\/boochlin.com\/wp-content\/uploads\/2015\/03\/system.jpg\" alt=\"system\" width=\"1280\" height=\"676\" \/><\/a><\/p>\n<h4><strong>Q2:\u70ba\u4f55\u70ba\u4f55 captureSession \u6642\uff0c\u6703\u653e\u5165outputSurface(Surface[]) \u591a\u500bsurface \u800c\u4e26<span style=\"color: #0000ff;\">\u975e\u6307\u5b9a\u55ae\u4e00surface?<\/span><\/strong><\/h4>\n<p>A2:\u518d\u5275\u5efaCameraCaptureSession \u901a\u5e38\u6703\u653e\u5165\u672a\u4f86\u53ef\u80fd\u6703\u7528\u5230\u7684target surfaces \uff0c\u4e26\u4e0d\u6703\u53ea\u653e\u5165\u55ae\u4e00\u7684target surface \uff0c\u800c\u55ae\u4e00\u6307\u5b9asurface \u7684\u9700\u6c42\u5beb\u5165capture request\u88e1<\/p>\n<h4><strong>Q3:ImageReader \u4f7f\u7528\u65b9\u6cd5\uff1f<\/strong><\/h4>\n<p>A3:Use ImageReader.getSurface() to get a Surface that can be used to produce Images for this ImageReader.<\/p>\n<h4><strong>Q3-1:what is surface?<\/strong><\/h4>\n<p>A3-1:<br \/>\n1.Handle onto a raw buffer that is being managed by the screen compositor.<br \/>\n2. surface \u7684canvas\u6210\u54e1\u53ef\u4ee5\u7528\u4f86\u63d0\u4f9b\u7e6a\u5716\u7684\u5834\u6240\uff0craw buffer \u7528\u4f86\u4fdd\u5b58data \uff0c\u53d6\u5f97surface \u7b49\u540c\u53d6\u5f97canvas \u548c raw buffer\u7684\u5167\u5bb9\u3002<br \/>\nsummary: \u65bccamera ap \u88e1\u5247\u662f\u7b49\u540c\u63d0\u4f9bcapture\u8f38\u51fadata\u7684\u7684\u76ee\u6a19surface\uff0c\u63a5\u8005imagereader\u6703\u5f9esurface \u53bb\u5c01\u88dddata\u8b8a\u6210image class\u3002<br \/>\n\u4e0b\u4e00\u7ae0\u7bc0\u6703\u4f86\u63a2\u8a0e Camera2 framework.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to create a camera 2 How to create a camera2<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[4],"_links":{"self":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/30"}],"collection":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=30"}],"version-history":[{"count":0,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/30\/revisions"}],"wp:attachment":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=30"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=30"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}