• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 拍照开发指导<a name="ZH-CN_TOPIC_0000001054915940"></a>
2
3-   [使用场景](#zh-cn_topic_0000001052170554_section1963312376119)
4-   [接口说明](#zh-cn_topic_0000001052170554_section56549532016)
5-   [约束与限制](#zh-cn_topic_0000001052170554_section1165911177314)
6-   [开发步骤](#zh-cn_topic_0000001052170554_section138543918214)
7
8## 使用场景<a name="zh-cn_topic_0000001052170554_section1963312376119"></a>
9
10使用Camera产生图片帧(拍照)。
11
12## 接口说明<a name="zh-cn_topic_0000001052170554_section56549532016"></a>
13
14**表 1**  API列表
15
16<a name="zh-cn_topic_0000001052170554_table2069447114914"></a>
17<table><thead align="left"><tr id="zh-cn_topic_0000001052170554_row4903852104914"><th class="cellrowborder" valign="top" width="14.93%" id="mcps1.2.4.1.1"><p id="zh-cn_topic_0000001052170554_p2903252174918"><a name="zh-cn_topic_0000001052170554_p2903252174918"></a><a name="zh-cn_topic_0000001052170554_p2903252174918"></a>类名</p>
18</th>
19<th class="cellrowborder" valign="top" width="61.660000000000004%" id="mcps1.2.4.1.2"><p id="zh-cn_topic_0000001052170554_p1595113912507"><a name="zh-cn_topic_0000001052170554_p1595113912507"></a><a name="zh-cn_topic_0000001052170554_p1595113912507"></a>接口名</p>
20</th>
21<th class="cellrowborder" valign="top" width="23.41%" id="mcps1.2.4.1.3"><p id="zh-cn_topic_0000001052170554_p15951597508"><a name="zh-cn_topic_0000001052170554_p15951597508"></a><a name="zh-cn_topic_0000001052170554_p15951597508"></a>描述</p>
22</th>
23</tr>
24</thead>
25<tbody><tr id="zh-cn_topic_0000001052170554_row492815717494"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p1592812716495"><a name="zh-cn_topic_0000001052170554_p1592812716495"></a><a name="zh-cn_topic_0000001052170554_p1592812716495"></a>CameraKit</p>
26</td>
27<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p1492837144919"><a name="zh-cn_topic_0000001052170554_p1492837144919"></a><a name="zh-cn_topic_0000001052170554_p1492837144919"></a>int32_t GetCameraIds(std::list&lt;string&gt; cameraList)</p>
28</td>
29<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p2092807134919"><a name="zh-cn_topic_0000001052170554_p2092807134919"></a><a name="zh-cn_topic_0000001052170554_p2092807134919"></a>获取cameraId列表</p>
30</td>
31</tr>
32<tr id="zh-cn_topic_0000001052170554_row11928157114912"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p139287774911"><a name="zh-cn_topic_0000001052170554_p139287774911"></a><a name="zh-cn_topic_0000001052170554_p139287774911"></a>CameraKit</p>
33</td>
34<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p9928107174915"><a name="zh-cn_topic_0000001052170554_p9928107174915"></a><a name="zh-cn_topic_0000001052170554_p9928107174915"></a>CameraAbility&amp; GetCameraAbility(string cameraId)</p>
35</td>
36<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p139281171494"><a name="zh-cn_topic_0000001052170554_p139281171494"></a><a name="zh-cn_topic_0000001052170554_p139281171494"></a>获取指定camera的能力</p>
37</td>
38</tr>
39<tr id="zh-cn_topic_0000001052170554_row119282719496"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p159288734914"><a name="zh-cn_topic_0000001052170554_p159288734914"></a><a name="zh-cn_topic_0000001052170554_p159288734914"></a>CameraKit</p>
40</td>
41<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p99280794913"><a name="zh-cn_topic_0000001052170554_p99280794913"></a><a name="zh-cn_topic_0000001052170554_p99280794913"></a>void RegisterCameraDeviceCallback(CameraDeviceCallback* callback, EventHandler* handler)</p>
42</td>
43<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p8928197134910"><a name="zh-cn_topic_0000001052170554_p8928197134910"></a><a name="zh-cn_topic_0000001052170554_p8928197134910"></a>注册camera设备状态回调</p>
44</td>
45</tr>
46<tr id="zh-cn_topic_0000001052170554_row4928673496"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p14928770497"><a name="zh-cn_topic_0000001052170554_p14928770497"></a><a name="zh-cn_topic_0000001052170554_p14928770497"></a>CameraKit</p>
47</td>
48<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p14928197194915"><a name="zh-cn_topic_0000001052170554_p14928197194915"></a><a name="zh-cn_topic_0000001052170554_p14928197194915"></a>void UnregisterCameraDeviceCallback(CameraDeviceCallback* callback)</p>
49</td>
50<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p17929197134913"><a name="zh-cn_topic_0000001052170554_p17929197134913"></a><a name="zh-cn_topic_0000001052170554_p17929197134913"></a>去注册camera设备状态回调</p>
51</td>
52</tr>
53<tr id="zh-cn_topic_0000001052170554_row16929187104912"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p6929157184911"><a name="zh-cn_topic_0000001052170554_p6929157184911"></a><a name="zh-cn_topic_0000001052170554_p6929157184911"></a>CameraKit</p>
54</td>
55<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p1192910704914"><a name="zh-cn_topic_0000001052170554_p1192910704914"></a><a name="zh-cn_topic_0000001052170554_p1192910704914"></a>void CreateCamera(string cameraId, CameraStateCallback* callback, EventHandler* handler)</p>
56</td>
57<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p12929167154912"><a name="zh-cn_topic_0000001052170554_p12929167154912"></a><a name="zh-cn_topic_0000001052170554_p12929167154912"></a>创建camera实例</p>
58</td>
59</tr>
60<tr id="zh-cn_topic_0000001052170554_row592967184912"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p9929127134915"><a name="zh-cn_topic_0000001052170554_p9929127134915"></a><a name="zh-cn_topic_0000001052170554_p9929127134915"></a>Camera</p>
61</td>
62<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p0929107204913"><a name="zh-cn_topic_0000001052170554_p0929107204913"></a><a name="zh-cn_topic_0000001052170554_p0929107204913"></a>string GetCameraId()</p>
63</td>
64<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p1592914710490"><a name="zh-cn_topic_0000001052170554_p1592914710490"></a><a name="zh-cn_topic_0000001052170554_p1592914710490"></a>获取cameraID</p>
65</td>
66</tr>
67<tr id="zh-cn_topic_0000001052170554_row13929197104913"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p16929167134913"><a name="zh-cn_topic_0000001052170554_p16929167134913"></a><a name="zh-cn_topic_0000001052170554_p16929167134913"></a>Camera</p>
68</td>
69<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p15929175491"><a name="zh-cn_topic_0000001052170554_p15929175491"></a><a name="zh-cn_topic_0000001052170554_p15929175491"></a>CameraConfig&amp; GetCameraConfig()</p>
70</td>
71<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p19298714917"><a name="zh-cn_topic_0000001052170554_p19298714917"></a><a name="zh-cn_topic_0000001052170554_p19298714917"></a>获取camera配置信息</p>
72</td>
73</tr>
74<tr id="zh-cn_topic_0000001052170554_row1892918764915"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p69291072495"><a name="zh-cn_topic_0000001052170554_p69291072495"></a><a name="zh-cn_topic_0000001052170554_p69291072495"></a>Camera</p>
75</td>
76<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p5930172494"><a name="zh-cn_topic_0000001052170554_p5930172494"></a><a name="zh-cn_topic_0000001052170554_p5930172494"></a>FrameConfig&amp; GetFrameConfig(int32_t type)</p>
77</td>
78<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p19301176495"><a name="zh-cn_topic_0000001052170554_p19301176495"></a><a name="zh-cn_topic_0000001052170554_p19301176495"></a>获取捕获帧类型</p>
79</td>
80</tr>
81<tr id="zh-cn_topic_0000001052170554_row893019794915"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p893016714919"><a name="zh-cn_topic_0000001052170554_p893016714919"></a><a name="zh-cn_topic_0000001052170554_p893016714919"></a>Camera</p>
82</td>
83<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p1093067134915"><a name="zh-cn_topic_0000001052170554_p1093067134915"></a><a name="zh-cn_topic_0000001052170554_p1093067134915"></a>void Configure(CameraConfig&amp; config)</p>
84</td>
85<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p1493037114912"><a name="zh-cn_topic_0000001052170554_p1493037114912"></a><a name="zh-cn_topic_0000001052170554_p1493037114912"></a>配置camera</p>
86</td>
87</tr>
88<tr id="zh-cn_topic_0000001052170554_row11930197174917"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p4930197184914"><a name="zh-cn_topic_0000001052170554_p4930197184914"></a><a name="zh-cn_topic_0000001052170554_p4930197184914"></a>Camera</p>
89</td>
90<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p19304717492"><a name="zh-cn_topic_0000001052170554_p19304717492"></a><a name="zh-cn_topic_0000001052170554_p19304717492"></a>void Release()</p>
91</td>
92<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p189301479494"><a name="zh-cn_topic_0000001052170554_p189301479494"></a><a name="zh-cn_topic_0000001052170554_p189301479494"></a>释放camera</p>
93</td>
94</tr>
95<tr id="zh-cn_topic_0000001052170554_row109304717499"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p4930873496"><a name="zh-cn_topic_0000001052170554_p4930873496"></a><a name="zh-cn_topic_0000001052170554_p4930873496"></a>Camera</p>
96</td>
97<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p1893017720490"><a name="zh-cn_topic_0000001052170554_p1893017720490"></a><a name="zh-cn_topic_0000001052170554_p1893017720490"></a>int TriggerLoopingCapture(FrameConfig&amp; frameConfig)</p>
98</td>
99<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p149307754918"><a name="zh-cn_topic_0000001052170554_p149307754918"></a><a name="zh-cn_topic_0000001052170554_p149307754918"></a>开始循环帧捕获</p>
100</td>
101</tr>
102<tr id="zh-cn_topic_0000001052170554_row19306794915"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p6930167194910"><a name="zh-cn_topic_0000001052170554_p6930167194910"></a><a name="zh-cn_topic_0000001052170554_p6930167194910"></a>Camera</p>
103</td>
104<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p139311577499"><a name="zh-cn_topic_0000001052170554_p139311577499"></a><a name="zh-cn_topic_0000001052170554_p139311577499"></a>void StopLoopingCapture()</p>
105</td>
106<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p693115764914"><a name="zh-cn_topic_0000001052170554_p693115764914"></a><a name="zh-cn_topic_0000001052170554_p693115764914"></a>停止循环帧捕获</p>
107</td>
108</tr>
109<tr id="zh-cn_topic_0000001052170554_row593116713492"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p1193187174913"><a name="zh-cn_topic_0000001052170554_p1193187174913"></a><a name="zh-cn_topic_0000001052170554_p1193187174913"></a>Camera</p>
110</td>
111<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p1493111713496"><a name="zh-cn_topic_0000001052170554_p1493111713496"></a><a name="zh-cn_topic_0000001052170554_p1493111713496"></a>int32_t TriggerSingleCapture(FrameConfig&amp; frameConfig)</p>
112</td>
113<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p1193137104919"><a name="zh-cn_topic_0000001052170554_p1193137104919"></a><a name="zh-cn_topic_0000001052170554_p1193137104919"></a>抓图</p>
114</td>
115</tr>
116<tr id="zh-cn_topic_0000001052170554_row1693112711491"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p89312716494"><a name="zh-cn_topic_0000001052170554_p89312716494"></a><a name="zh-cn_topic_0000001052170554_p89312716494"></a>CameraConfig</p>
117</td>
118<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p199312784912"><a name="zh-cn_topic_0000001052170554_p199312784912"></a><a name="zh-cn_topic_0000001052170554_p199312784912"></a>void SetFrameStateCallback(FrameStateCallback* callback, EventHandler* handler);</p>
119</td>
120<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p49312714495"><a name="zh-cn_topic_0000001052170554_p49312714495"></a><a name="zh-cn_topic_0000001052170554_p49312714495"></a>设置帧状态回调</p>
121</td>
122</tr>
123<tr id="zh-cn_topic_0000001052170554_row9931076492"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p59317784917"><a name="zh-cn_topic_0000001052170554_p59317784917"></a><a name="zh-cn_topic_0000001052170554_p59317784917"></a>CameraConfig</p>
124</td>
125<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p17931197124912"><a name="zh-cn_topic_0000001052170554_p17931197124912"></a><a name="zh-cn_topic_0000001052170554_p17931197124912"></a>static CameraConfig* CreateCameraConfig()</p>
126</td>
127<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p5931177164912"><a name="zh-cn_topic_0000001052170554_p5931177164912"></a><a name="zh-cn_topic_0000001052170554_p5931177164912"></a>创建camera配置信息实例</p>
128</td>
129</tr>
130<tr id="zh-cn_topic_0000001052170554_row29321744917"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p1093219716492"><a name="zh-cn_topic_0000001052170554_p1093219716492"></a><a name="zh-cn_topic_0000001052170554_p1093219716492"></a>CameraAbility</p>
131</td>
132<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p12932979493"><a name="zh-cn_topic_0000001052170554_p12932979493"></a><a name="zh-cn_topic_0000001052170554_p12932979493"></a>std::list&lt;Size&gt; GetSupportedSizes(int format)</p>
133</td>
134<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p1493210764918"><a name="zh-cn_topic_0000001052170554_p1493210764918"></a><a name="zh-cn_topic_0000001052170554_p1493210764918"></a>根据类型获取支持输出图像尺寸大小</p>
135</td>
136</tr>
137<tr id="zh-cn_topic_0000001052170554_row1193267184910"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p1393214717492"><a name="zh-cn_topic_0000001052170554_p1393214717492"></a><a name="zh-cn_topic_0000001052170554_p1393214717492"></a>CameraAbility</p>
138</td>
139<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p119321477495"><a name="zh-cn_topic_0000001052170554_p119321477495"></a><a name="zh-cn_topic_0000001052170554_p119321477495"></a>std::list&lt;T&gt; GetParameterRange(uint32_t key)</p>
140</td>
141<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p139331079491"><a name="zh-cn_topic_0000001052170554_p139331079491"></a><a name="zh-cn_topic_0000001052170554_p139331079491"></a>获取支持的参数范围</p>
142</td>
143</tr>
144<tr id="zh-cn_topic_0000001052170554_row0933197134920"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p1493310764917"><a name="zh-cn_topic_0000001052170554_p1493310764917"></a><a name="zh-cn_topic_0000001052170554_p1493310764917"></a>CameraDevice</p>
145</td>
146<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p493313724915"><a name="zh-cn_topic_0000001052170554_p493313724915"></a><a name="zh-cn_topic_0000001052170554_p493313724915"></a>CameraDeviceCallback()</p>
147</td>
148<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p993416724915"><a name="zh-cn_topic_0000001052170554_p993416724915"></a><a name="zh-cn_topic_0000001052170554_p993416724915"></a>camera设备回调类构造函数</p>
149</td>
150</tr>
151<tr id="zh-cn_topic_0000001052170554_row093418712498"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p159341779492"><a name="zh-cn_topic_0000001052170554_p159341779492"></a><a name="zh-cn_topic_0000001052170554_p159341779492"></a>CameraDevice</p>
152</td>
153<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p1493411774912"><a name="zh-cn_topic_0000001052170554_p1493411774912"></a><a name="zh-cn_topic_0000001052170554_p1493411774912"></a>void OnCameraStatus​(std::string cameraId, int32_t status)</p>
154</td>
155<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p1393419715491"><a name="zh-cn_topic_0000001052170554_p1393419715491"></a><a name="zh-cn_topic_0000001052170554_p1393419715491"></a>camera设备状态变化时的回调</p>
156</td>
157</tr>
158<tr id="zh-cn_topic_0000001052170554_row109348711497"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p993419724914"><a name="zh-cn_topic_0000001052170554_p993419724914"></a><a name="zh-cn_topic_0000001052170554_p993419724914"></a>CameraStateCallback</p>
159</td>
160<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p993418720497"><a name="zh-cn_topic_0000001052170554_p993418720497"></a><a name="zh-cn_topic_0000001052170554_p993418720497"></a>CameraStateCallback​()</p>
161</td>
162<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p693511794919"><a name="zh-cn_topic_0000001052170554_p693511794919"></a><a name="zh-cn_topic_0000001052170554_p693511794919"></a>camera状态回调类构造函数</p>
163</td>
164</tr>
165<tr id="zh-cn_topic_0000001052170554_row159358717497"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p1992012253527"><a name="zh-cn_topic_0000001052170554_p1992012253527"></a><a name="zh-cn_topic_0000001052170554_p1992012253527"></a>CameraStateCallback</p>
166</td>
167<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p29351077497"><a name="zh-cn_topic_0000001052170554_p29351077497"></a><a name="zh-cn_topic_0000001052170554_p29351077497"></a>void OnConfigured​(Camera&amp; camera)</p>
168</td>
169<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p093515774914"><a name="zh-cn_topic_0000001052170554_p093515774914"></a><a name="zh-cn_topic_0000001052170554_p093515774914"></a>camera配置成功回调</p>
170</td>
171</tr>
172<tr id="zh-cn_topic_0000001052170554_row9935147184918"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p117291328135211"><a name="zh-cn_topic_0000001052170554_p117291328135211"></a><a name="zh-cn_topic_0000001052170554_p117291328135211"></a>CameraStateCallback</p>
173</td>
174<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p19935174496"><a name="zh-cn_topic_0000001052170554_p19935174496"></a><a name="zh-cn_topic_0000001052170554_p19935174496"></a>void OnConfigureFailed​(Camera&amp; camera,int32_t errorCode)</p>
175</td>
176<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p159352077495"><a name="zh-cn_topic_0000001052170554_p159352077495"></a><a name="zh-cn_topic_0000001052170554_p159352077495"></a>camera配置失败回调</p>
177</td>
178</tr>
179<tr id="zh-cn_topic_0000001052170554_row1935279498"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p1514619311525"><a name="zh-cn_topic_0000001052170554_p1514619311525"></a><a name="zh-cn_topic_0000001052170554_p1514619311525"></a>CameraStateCallback</p>
180</td>
181<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p493512744915"><a name="zh-cn_topic_0000001052170554_p493512744915"></a><a name="zh-cn_topic_0000001052170554_p493512744915"></a>void OnCreated​(Camera&amp; camera)</p>
182</td>
183<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p1493511784914"><a name="zh-cn_topic_0000001052170554_p1493511784914"></a><a name="zh-cn_topic_0000001052170554_p1493511784914"></a>camera创建成功回调</p>
184</td>
185</tr>
186<tr id="zh-cn_topic_0000001052170554_row189351877493"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p172071933175218"><a name="zh-cn_topic_0000001052170554_p172071933175218"></a><a name="zh-cn_topic_0000001052170554_p172071933175218"></a>CameraStateCallback</p>
187</td>
188<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p129361977498"><a name="zh-cn_topic_0000001052170554_p129361977498"></a><a name="zh-cn_topic_0000001052170554_p129361977498"></a>void OnCreateFailed​(std::string cameraId,int32_t errorCode)</p>
189</td>
190<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p2936197114919"><a name="zh-cn_topic_0000001052170554_p2936197114919"></a><a name="zh-cn_topic_0000001052170554_p2936197114919"></a>camera创建失败回调</p>
191</td>
192</tr>
193<tr id="zh-cn_topic_0000001052170554_row20936472491"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p61213391523"><a name="zh-cn_topic_0000001052170554_p61213391523"></a><a name="zh-cn_topic_0000001052170554_p61213391523"></a>CameraStateCallback</p>
194</td>
195<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p793697174919"><a name="zh-cn_topic_0000001052170554_p793697174919"></a><a name="zh-cn_topic_0000001052170554_p793697174919"></a>void OnReleased​(Camera&amp; camera)</p>
196</td>
197<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p49361719495"><a name="zh-cn_topic_0000001052170554_p49361719495"></a><a name="zh-cn_topic_0000001052170554_p49361719495"></a>camera释放回调</p>
198</td>
199</tr>
200<tr id="zh-cn_topic_0000001052170554_row159361179493"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p10936147194918"><a name="zh-cn_topic_0000001052170554_p10936147194918"></a><a name="zh-cn_topic_0000001052170554_p10936147194918"></a>FrameStateCallback</p>
201</td>
202<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p9936279496"><a name="zh-cn_topic_0000001052170554_p9936279496"></a><a name="zh-cn_topic_0000001052170554_p9936279496"></a>FrameStateCallback​()</p>
203</td>
204<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p49367718499"><a name="zh-cn_topic_0000001052170554_p49367718499"></a><a name="zh-cn_topic_0000001052170554_p49367718499"></a>帧状态回调类构造函数</p>
205</td>
206</tr>
207<tr id="zh-cn_topic_0000001052170554_row1893617744916"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p136968511524"><a name="zh-cn_topic_0000001052170554_p136968511524"></a><a name="zh-cn_topic_0000001052170554_p136968511524"></a>FrameStateCallback</p>
208</td>
209<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p209379744911"><a name="zh-cn_topic_0000001052170554_p209379744911"></a><a name="zh-cn_topic_0000001052170554_p209379744911"></a>void OnFrameFinished(Camera&amp; camera, FrameConfig&amp; frameConfig, FrameResult&amp; frameResult)</p>
210</td>
211<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p19374724913"><a name="zh-cn_topic_0000001052170554_p19374724913"></a><a name="zh-cn_topic_0000001052170554_p19374724913"></a>拍照帧完成回调</p>
212</td>
213</tr>
214<tr id="zh-cn_topic_0000001052170554_row093719718495"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p772975317527"><a name="zh-cn_topic_0000001052170554_p772975317527"></a><a name="zh-cn_topic_0000001052170554_p772975317527"></a>FrameStateCallback</p>
215</td>
216<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p189371471498"><a name="zh-cn_topic_0000001052170554_p189371471498"></a><a name="zh-cn_topic_0000001052170554_p189371471498"></a>void OnFrameError​(Camera&amp; camera, FrameConfig&amp; frameConfig, int32_t errorCode, FrameResult&amp; frameResult)</p>
217</td>
218<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p109371778497"><a name="zh-cn_topic_0000001052170554_p109371778497"></a><a name="zh-cn_topic_0000001052170554_p109371778497"></a>拍照帧异常回调</p>
219</td>
220</tr>
221<tr id="zh-cn_topic_0000001052170554_row179381979499"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p169381975499"><a name="zh-cn_topic_0000001052170554_p169381975499"></a><a name="zh-cn_topic_0000001052170554_p169381975499"></a>FrameConfig</p>
222</td>
223<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p1793867124910"><a name="zh-cn_topic_0000001052170554_p1793867124910"></a><a name="zh-cn_topic_0000001052170554_p1793867124910"></a>int32_t GetFrameConfigType()</p>
224</td>
225<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p1993817744915"><a name="zh-cn_topic_0000001052170554_p1993817744915"></a><a name="zh-cn_topic_0000001052170554_p1993817744915"></a>获取帧配置类型</p>
226</td>
227</tr>
228<tr id="zh-cn_topic_0000001052170554_row793817784912"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p69381724914"><a name="zh-cn_topic_0000001052170554_p69381724914"></a><a name="zh-cn_topic_0000001052170554_p69381724914"></a>FrameConfig</p>
229</td>
230<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p149382077496"><a name="zh-cn_topic_0000001052170554_p149382077496"></a><a name="zh-cn_topic_0000001052170554_p149382077496"></a>std::list&lt;OHOS::Surface&gt; GetSurfaces()</p>
231</td>
232<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p893867114919"><a name="zh-cn_topic_0000001052170554_p893867114919"></a><a name="zh-cn_topic_0000001052170554_p893867114919"></a>获取帧配置的surface</p>
233</td>
234</tr>
235<tr id="zh-cn_topic_0000001052170554_row109401570498"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p294019712492"><a name="zh-cn_topic_0000001052170554_p294019712492"></a><a name="zh-cn_topic_0000001052170554_p294019712492"></a>FrameConfig</p>
236</td>
237<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p19940170499"><a name="zh-cn_topic_0000001052170554_p19940170499"></a><a name="zh-cn_topic_0000001052170554_p19940170499"></a>void AddSurface(OHOS::AGP::UISurface&amp; surface);</p>
238</td>
239<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p11940197144915"><a name="zh-cn_topic_0000001052170554_p11940197144915"></a><a name="zh-cn_topic_0000001052170554_p11940197144915"></a>添加surface</p>
240</td>
241</tr>
242<tr id="zh-cn_topic_0000001052170554_row994018711492"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="zh-cn_topic_0000001052170554_p1094016718493"><a name="zh-cn_topic_0000001052170554_p1094016718493"></a><a name="zh-cn_topic_0000001052170554_p1094016718493"></a>FrameConfig</p>
243</td>
244<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="zh-cn_topic_0000001052170554_p139411279498"><a name="zh-cn_topic_0000001052170554_p139411279498"></a><a name="zh-cn_topic_0000001052170554_p139411279498"></a>void RemoveSurface(OHOS::AGP::UISurface&amp; surface);</p>
245</td>
246<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="zh-cn_topic_0000001052170554_p39415717494"><a name="zh-cn_topic_0000001052170554_p39415717494"></a><a name="zh-cn_topic_0000001052170554_p39415717494"></a>删除surface</p>
247</td>
248</tr>
249</tbody>
250</table>
251
252## 约束与限制<a name="zh-cn_topic_0000001052170554_section1165911177314"></a>
253
254无。
255
256## 开发步骤<a name="zh-cn_topic_0000001052170554_section138543918214"></a>
257
2581.  <a name="zh-cn_topic_0000001052170554_li378084192111"></a>实现设备状态回调的派生类,用户在设备状态发生变更(如新插入相机设备/相机掉线)时,自定义操作。
259
260    ```
261    class SampleCameraDeviceCallback : public CameraDeviceCallback {
262        void OnCameraStatus(std::string cameraId, int32_t status) override
263        {
264            //do something when camera is available/unavailable
265        }
266    };
267    ```
268
2692.  <a name="zh-cn_topic_0000001052170554_li8716104682913"></a>实现帧事件回调的派生类,这里在拿到帧数据以后将其转存为文件。
270
271    ```
272    static void SampleSaveCapture(const char *p, uint32_t size)
273    {
274        cout << "Start saving picture" << endl;
275        struct timeval tv;
276        gettimeofday(&tv, NULL);
277        struct tm *ltm = localtime(&tv.tv_sec);
278        if (ltm != nullptr) {
279            ostringstream ss("Capture_");
280            ss << "Capture" << ltm->tm_hour << "-" << ltm->tm_min << "-" << ltm->tm_sec << ".jpg";
281
282            ofstream pic("/sdcard/" + ss.str(), ofstream::out | ofstream::trunc);
283            cout << "write " << size << " bytes" << endl;
284            pic.write(p, size);
285            cout << "Saving picture end" << endl;
286        }
287    }
288
289    class TestFrameStateCallback : public FrameStateCallback {
290        void OnFrameFinished(Camera &camera, FrameConfig &fc, FrameResult &result) override
291        {
292            cout << "Receive frame complete inform." << endl;
293            if (fc.GetFrameConfigType() == FRAME_CONFIG_CAPTURE) {
294                cout << "Capture frame received." << endl;
295                list<Surface *> surfaceList = fc.GetSurfaces();
296                for (Surface *surface : surfaceList) {
297                    SurfaceBuffer *buffer = surface->AcquireBuffer();
298                    if (buffer != nullptr) {
299                        char *virtAddr = static_cast<char *>(buffer->GetVirAddr());
300                        if (virtAddr != nullptr) {
301                            SampleSaveCapture(virtAddr, buffer->GetSize());
302                        }
303                        surface->ReleaseBuffer(buffer);
304                    }
305                    delete surface;
306                }
307                delete &fc;
308            }
309        }
310    };
311    ```
312
3133.  <a name="zh-cn_topic_0000001052170554_li6671035102514"></a>实现相机状态回调的派生类,自定义相机状态发生变化(配置成功/失败,创建成功/失败\)时的操作。
314
315    ```
316    class SampleCameraStateMng : public CameraStateCallback {
317    public:
318        SampleCameraStateMng() = delete;
319        SampleCameraStateMng(EventHandler &eventHdlr) : eventHdlr_(eventHdlr) {}
320        ~SampleCameraStateMng()
321        {
322            if (recordFd_ != -1) {
323                close(recordFd_);
324            }
325        }
326        void OnCreated(Camera &c) override
327        {
328            cout << "Sample recv OnCreate camera." << endl;
329            auto config = CameraConfig::CreateCameraConfig();
330            config->SetFrameStateCallback(&fsCb_, &eventHdlr_);
331            c.Configure(*config);
332            cam_ = &c;
333        }
334        void OnCreateFailed(const std::string cameraId, int32_t errorCode) override {}
335        void OnReleased(Camera &c) override {}
336    };
337    ```
338
3394.  创建CameraKit,用于创建和获取camera信息。
340
341    ```
342    CameraKit *camKit = CameraKit::GetInstance();
343    list<string> camList = camKit->GetCameraIds();
344    string camId;
345    for (auto &cam : camList) {
346        cout << "camera name:" << cam << endl;
347        const CameraAbility *ability = camKit->GetCameraAbility(cam);
348        /* find camera which fits user's ability */
349        list<CameraPicSize> sizeList = ability->GetSupportedSizes(0);
350        if (find(sizeList.begin(), sizeList.end(), CAM_PIC_1080P) != sizeList.end()) {
351            camId = cam;
352            break;
353        }
354    }
355    ```
356
3575.  创建Camera实例。
358
359    ```
360    EventHandler eventHdlr; // Create a thread to handle callback events
361    SampleCameraStateMng CamStateMng(eventHdlr);
362
363    camKit->CreateCamera(camId, CamStateMng, eventHdlr);
364    ```
365
3666.  根据[步骤1](#zh-cn_topic_0000001052170554_li378084192111)、[步骤2](#zh-cn_topic_0000001052170554_li8716104682913)、[步骤3](#zh-cn_topic_0000001052170554_li6671035102514)中的回调设计,同步等待 OnCreated 回调拿到 cam\_ 之后,进行相关操作。
367
368    ```
369    void OnCreated(Camera &c) override
370    {
371        cout << "Sample recv OnCreate camera." << endl;
372        auto config = CameraConfig::CreateCameraConfig();
373        config->SetFrameStateCallback(&fsCb_, &eventHdlr_);
374        c.Configure(*config);
375        cam_ = &c;
376    }
377
378    void Capture()
379    {
380        if (cam_ == nullptr) {
381            cout << "Camera is not ready." << endl;
382            return;
383        }
384        FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE);
385        Surface *surface = Surface::CreateSurface();
386        if (surface == nullptr) {
387            delete fc;
388            return;
389        }
390        surface->SetWidthAndHeight(1920, 1080); /* 1920:width,1080:height */
391        fc->AddSurface(*surface);
392        cam_->TriggerSingleCapture(*fc);
393    }
394    ```
395
396
397