• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Photographing Development<a name="EN-US_TOPIC_0000001052170554"></a>
2
3## When to Use<a name="section1963312376119"></a>
4
5Use the camera module APIs to capture frames \(photographing\).
6
7## Available APIs<a name="section56549532016"></a>
8
9**Table  1**  APIs for photographing
10
11<a name="table2069447114914"></a>
12<table><thead align="left"><tr id="row4903852104914"><th class="cellrowborder" valign="top" width="18.811881188118814%" id="mcps1.2.4.1.1"><p id="p2903252174918"><a name="p2903252174918"></a><a name="p2903252174918"></a>Class</p>
13</th>
14<th class="cellrowborder" valign="top" width="46.534653465346544%" id="mcps1.2.4.1.2"><p id="p1595113912507"><a name="p1595113912507"></a><a name="p1595113912507"></a>Function</p>
15</th>
16<th class="cellrowborder" valign="top" width="34.65346534653466%" id="mcps1.2.4.1.3"><p id="p15951597508"><a name="p15951597508"></a><a name="p15951597508"></a>Description</p>
17</th>
18</tr>
19</thead>
20<tbody><tr id="row492815717494"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p1592812716495"><a name="p1592812716495"></a><a name="p1592812716495"></a>CameraKit</p>
21</td>
22<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p1492837144919"><a name="p1492837144919"></a><a name="p1492837144919"></a>int32_t GetCameraIds(std::list&lt;string&gt; cameraList)</p>
23</td>
24<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p2092807134919"><a name="p2092807134919"></a><a name="p2092807134919"></a>Obtains IDs of cameras that are currently available.</p>
25</td>
26</tr>
27<tr id="row11928157114912"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p139287774911"><a name="p139287774911"></a><a name="p139287774911"></a>CameraKit</p>
28</td>
29<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p9928107174915"><a name="p9928107174915"></a><a name="p9928107174915"></a>CameraAbility&amp; GetCameraAbility(string cameraId)</p>
30</td>
31<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p139281171494"><a name="p139281171494"></a><a name="p139281171494"></a>Obtains the camera capability</p>
32</td>
33</tr>
34<tr id="row119282719496"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p159288734914"><a name="p159288734914"></a><a name="p159288734914"></a>CameraKit</p>
35</td>
36<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p99280794913"><a name="p99280794913"></a><a name="p99280794913"></a>void RegisterCameraDeviceCallback(CameraDeviceCallback* callback, EventHandler* handler)</p>
37</td>
38<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p8928197134910"><a name="p8928197134910"></a><a name="p8928197134910"></a>Registers a camera callback for camera status changes.</p>
39</td>
40</tr>
41<tr id="row4928673496"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p14928770497"><a name="p14928770497"></a><a name="p14928770497"></a>CameraKit</p>
42</td>
43<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p14928197194915"><a name="p14928197194915"></a><a name="p14928197194915"></a>void UnregisterCameraDeviceCallback(CameraDeviceCallback* callback)</p>
44</td>
45<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p17929197134913"><a name="p17929197134913"></a><a name="p17929197134913"></a>Unregisters a camera callback.</p>
46</td>
47</tr>
48<tr id="row16929187104912"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p6929157184911"><a name="p6929157184911"></a><a name="p6929157184911"></a>CameraKit</p>
49</td>
50<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p1192910704914"><a name="p1192910704914"></a><a name="p1192910704914"></a>void CreateCamera(string cameraId, CameraStateCallback* callback, EventHandler* handler)</p>
51</td>
52<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p12929167154912"><a name="p12929167154912"></a><a name="p12929167154912"></a>Creates a <strong id="b1512582132318"><a name="b1512582132318"></a><a name="b1512582132318"></a>Camera</strong> instance.</p>
53</td>
54</tr>
55<tr id="row16929187104913"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="p6929157184911"><a name="p6929157184911"></a><a name="p6929157184911"></a>CameraKit</p>
56</td>
57<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="p1192910704914"><a name="p1192910704914"></a><a name="p1192910704914"></a>const CameraInfo *GetCameraInfo(std::string cameraId);</p>
58</td>
59<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="p12929167154912"><a name="p12929167154912"></a><a name="p12929167154912"></a>Creates a <strong id="b1512582132318"><a name="b1512582132318"></a><a name="b1512582132318"></a>CameraInfo</strong> instance.</p>
60</td>
61</tr>
62<tr id="row592967184912"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p9929127134915"><a name="p9929127134915"></a><a name="p9929127134915"></a>Camera</p>
63</td>
64<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p0929107204913"><a name="p0929107204913"></a><a name="p0929107204913"></a>string GetCameraId()</p>
65</td>
66<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p1592914710490"><a name="p1592914710490"></a><a name="p1592914710490"></a>Obtains the camera ID.</p>
67</td>
68</tr>
69<tr id="row13929197104913"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p16929167134913"><a name="p16929167134913"></a><a name="p16929167134913"></a>Camera</p>
70</td>
71<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p15929175491"><a name="p15929175491"></a><a name="p15929175491"></a>CameraConfig&amp; GetCameraConfig()</p>
72</td>
73<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p19298714917"><a name="p19298714917"></a><a name="p19298714917"></a>Obtains the camera configuration.</p>
74</td>
75</tr>
76<tr id="row1892918764915"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p69291072495"><a name="p69291072495"></a><a name="p69291072495"></a>Camera</p>
77</td>
78<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p5930172494"><a name="p5930172494"></a><a name="p5930172494"></a>FrameConfig&amp; GetFrameConfig(int32_t type)</p>
79</td>
80<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p19301176495"><a name="p19301176495"></a><a name="p19301176495"></a>Obtains the frame configuration.</p>
81</td>
82</tr>
83<tr id="row893019794915"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p893016714919"><a name="p893016714919"></a><a name="p893016714919"></a>Camera</p>
84</td>
85<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p1093067134915"><a name="p1093067134915"></a><a name="p1093067134915"></a>void Configure(CameraConfig&amp; config)</p>
86</td>
87<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p1493037114912"><a name="p1493037114912"></a><a name="p1493037114912"></a>Configures the camera using the <strong id="b1158653521815"><a name="b1158653521815"></a><a name="b1158653521815"></a>CameraConfig</strong> object.</p>
88</td>
89</tr>
90<tr id="row11930197174917"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p4930197184914"><a name="p4930197184914"></a><a name="p4930197184914"></a>Camera</p>
91</td>
92<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p19304717492"><a name="p19304717492"></a><a name="p19304717492"></a>void Release()</p>
93</td>
94<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p189301479494"><a name="p189301479494"></a><a name="p189301479494"></a>Releases the <strong id="b12391143101812"><a name="b12391143101812"></a><a name="b12391143101812"></a>Camera</strong> object and associated resources.</p>
95</td>
96</tr>
97<tr id="row109304717499"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p4930873496"><a name="p4930873496"></a><a name="p4930873496"></a>Camera</p>
98</td>
99<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p1893017720490"><a name="p1893017720490"></a><a name="p1893017720490"></a>int TriggerLoopingCapture(FrameConfig&amp; frameConfig)</p>
100</td>
101<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p149307754918"><a name="p149307754918"></a><a name="p149307754918"></a>Starts looping-frame capture.</p>
102</td>
103</tr>
104<tr id="row19306794915"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p6930167194910"><a name="p6930167194910"></a><a name="p6930167194910"></a>Camera</p>
105</td>
106<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p139311577499"><a name="p139311577499"></a><a name="p139311577499"></a>void StopLoopingCapture()</p>
107</td>
108<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p693115764914"><a name="p693115764914"></a><a name="p693115764914"></a>Stops looping-frame capture.</p>
109</td>
110</tr>
111<tr id="row593116713492"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p1193187174913"><a name="p1193187174913"></a><a name="p1193187174913"></a>Camera</p>
112</td>
113<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p1493111713496"><a name="p1493111713496"></a><a name="p1493111713496"></a>int32_t TriggerSingleCapture(FrameConfig&amp; frameConfig)</p>
114</td>
115<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p1193137104919"><a name="p1193137104919"></a><a name="p1193137104919"></a>Starts single-frame capture.</p>
116</td>
117</tr>
118<tr id="row1693112711491"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p89312716494"><a name="p89312716494"></a><a name="p89312716494"></a>CameraConfig</p>
119</td>
120<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p199312784912"><a name="p199312784912"></a><a name="p199312784912"></a>void SetFrameStateCallback(FrameStateCallback* callback, EventHandler* handler);</p>
121</td>
122<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p49312714495"><a name="p49312714495"></a><a name="p49312714495"></a>Sets a frame state callback to respond to state changes.</p>
123</td>
124</tr>
125<tr id="row9931076492"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p59317784917"><a name="p59317784917"></a><a name="p59317784917"></a>CameraConfig</p>
126</td>
127<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p17931197124912"><a name="p17931197124912"></a><a name="p17931197124912"></a>static CameraConfig* CreateCameraConfig()</p>
128</td>
129<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p5931177164912"><a name="p5931177164912"></a><a name="p5931177164912"></a>Creates a <strong id="b101608165182"><a name="b101608165182"></a><a name="b101608165182"></a>CameraConfig</strong> instance.</p>
130</td>
131</tr>
132<tr id="row29321744917"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p1093219716492"><a name="p1093219716492"></a><a name="p1093219716492"></a>CameraAbility</p>
133</td>
134<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p12932979493"><a name="p12932979493"></a><a name="p12932979493"></a>std::list&lt;Size&gt; GetSupportedSizes(int format)</p>
135</td>
136<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p1493210764918"><a name="p1493210764918"></a><a name="p1493210764918"></a>Obtains the supported image sizes for a specified image format.</p>
137</td>
138</tr>
139<tr id="row1193267184910"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p1393214717492"><a name="p1393214717492"></a><a name="p1393214717492"></a>CameraAbility</p>
140</td>
141<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p119321477495"><a name="p119321477495"></a><a name="p119321477495"></a>std::list&lt;T&gt; GetParameterRange(uint32_t key)</p>
142</td>
143<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p139331079491"><a name="p139331079491"></a><a name="p139331079491"></a>Obtains the parameter value range based on a specified parameter key.</p>
144</td>
145</tr>
146<tr id="row1193267184911"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="p1393214717492"><a name="p1393214717492"></a><a name="p1393214717492"></a>CameraAbility</p>
147</td>
148<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="p119321477495"><a name="p119321477495"></a><a name="p119321477495"></a>std::list&lt;int32_t&gt; GetSupportedAfModes() const;</p>
149</td>
150<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="p139331079491"><a name="p139331079491"></a><a name="p139331079491"></a>Gets a list of supported autofocus modes.</p>
151</td>
152</tr>
153<tr id="row1193267184912"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="p1393214717492"><a name="p1393214717492"></a><a name="p1393214717492"></a>CameraAbility</p>
154</td>
155<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="p119321477495"><a name="p119321477495"></a><a name="p119321477495"></a>std::list&lt;int32_t&gt; GetSupportedAeModes() const;</p>
156</td>
157<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="p139331079491"><a name="p139331079491"></a><a name="p139331079491"></a>Gets a list of supported auto exposure modes.</p>
158</td>
159</tr>
160<tr id="row0933197134920"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p1493310764917"><a name="p1493310764917"></a><a name="p1493310764917"></a>CameraDevice</p>
161</td>
162<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p493313724915"><a name="p493313724915"></a><a name="p493313724915"></a>CameraDeviceCallback()</p>
163</td>
164<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p993416724915"><a name="p993416724915"></a><a name="p993416724915"></a>A constructor used to create a <strong id="b99481043111719"><a name="b99481043111719"></a><a name="b99481043111719"></a>CameraDeviceCallback</strong> instance.</p>
165</td>
166</tr>
167<tr id="row093418712498"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p159341779492"><a name="p159341779492"></a><a name="p159341779492"></a>CameraDevice</p>
168</td>
169<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p1493411774912"><a name="p1493411774912"></a><a name="p1493411774912"></a>void OnCameraStatus​(std::string cameraId, int32_t status)</p>
170</td>
171<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p1393419715491"><a name="p1393419715491"></a><a name="p1393419715491"></a>Called when the camera device status changes.</p>
172</td>
173</tr>
174<tr id="row109348711497"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p993419724914"><a name="p993419724914"></a><a name="p993419724914"></a>CameraStateCallback</p>
175</td>
176<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p993418720497"><a name="p993418720497"></a><a name="p993418720497"></a>CameraStateCallback​()</p>
177</td>
178<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p693511794919"><a name="p693511794919"></a><a name="p693511794919"></a>A constructor used to create a <strong id="b10634201491717"><a name="b10634201491717"></a><a name="b10634201491717"></a>CameraStateCallback</strong> instance.</p>
179</td>
180</tr>
181<tr id="row159358717497"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p1992012253527"><a name="p1992012253527"></a><a name="p1992012253527"></a>CameraStateCallback</p>
182</td>
183<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p29351077497"><a name="p29351077497"></a><a name="p29351077497"></a>void OnConfigured​(Camera&amp; camera)</p>
184</td>
185<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p093515774914"><a name="p093515774914"></a><a name="p093515774914"></a>Called when the camera is configured.</p>
186</td>
187</tr>
188<tr id="row9935147184918"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p117291328135211"><a name="p117291328135211"></a><a name="p117291328135211"></a>CameraStateCallback</p>
189</td>
190<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p19935174496"><a name="p19935174496"></a><a name="p19935174496"></a>void OnConfigureFailed​(Camera&amp; camera,int32_t errorCode)</p>
191</td>
192<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p159352077495"><a name="p159352077495"></a><a name="p159352077495"></a>Called when the camera fails to be configured.</p>
193</td>
194</tr>
195<tr id="row1935279498"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p1514619311525"><a name="p1514619311525"></a><a name="p1514619311525"></a>CameraStateCallback</p>
196</td>
197<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p493512744915"><a name="p493512744915"></a><a name="p493512744915"></a>void OnCreated​(Camera&amp; camera)</p>
198</td>
199<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p1493511784914"><a name="p1493511784914"></a><a name="p1493511784914"></a>Called when the camera is successfully created.</p>
200</td>
201</tr>
202<tr id="row189351877493"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p172071933175218"><a name="p172071933175218"></a><a name="p172071933175218"></a>CameraStateCallback</p>
203</td>
204<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p129361977498"><a name="p129361977498"></a><a name="p129361977498"></a>void OnCreateFailed​(std::string cameraId,int32_t errorCode)</p>
205</td>
206<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p2936197114919"><a name="p2936197114919"></a><a name="p2936197114919"></a>Called when the camera fails to be created.</p>
207</td>
208</tr>
209<tr id="row20936472491"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p61213391523"><a name="p61213391523"></a><a name="p61213391523"></a>CameraStateCallback</p>
210</td>
211<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p793697174919"><a name="p793697174919"></a><a name="p793697174919"></a>void OnReleased​(Camera&amp; camera)</p>
212</td>
213<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p49361719495"><a name="p49361719495"></a><a name="p49361719495"></a>Called when the camera is released.</p>
214</td>
215</tr>
216<tr id="row159361179493"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p10936147194918"><a name="p10936147194918"></a><a name="p10936147194918"></a>FrameStateCallback</p>
217</td>
218<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p9936279496"><a name="p9936279496"></a><a name="p9936279496"></a>FrameStateCallback​()</p>
219</td>
220<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p49367718499"><a name="p49367718499"></a><a name="p49367718499"></a>A constructor used to create a <strong id="b225612012172"><a name="b225612012172"></a><a name="b225612012172"></a>FrameStateCallback</strong> instance.</p>
221</td>
222</tr>
223<tr id="row1893617744916"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p136968511524"><a name="p136968511524"></a><a name="p136968511524"></a>FrameStateCallback</p>
224</td>
225<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p209379744911"><a name="p209379744911"></a><a name="p209379744911"></a>void OnFrameFinished(Camera&amp; camera, FrameConfig&amp; frameConfig, FrameResult&amp; frameResult)</p>
226</td>
227<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p19374724913"><a name="p19374724913"></a><a name="p19374724913"></a>Called when the frame capture is completed.</p>
228</td>
229</tr>
230<tr id="row093719718495"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p772975317527"><a name="p772975317527"></a><a name="p772975317527"></a>FrameStateCallback</p>
231</td>
232<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p189371471498"><a name="p189371471498"></a><a name="p189371471498"></a>void OnFrameError​(Camera&amp; camera, FrameConfig&amp; frameConfig, int32_t errorCode, FrameResult&amp; frameResult)</p>
233</td>
234<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p109371778497"><a name="p109371778497"></a><a name="p109371778497"></a>Called when the frame capture fails.</p>
235</td>
236</tr>
237<tr id="row179381979499"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p169381975499"><a name="p169381975499"></a><a name="p169381975499"></a>FrameConfig</p>
238</td>
239<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p1793867124910"><a name="p1793867124910"></a><a name="p1793867124910"></a>int32_t GetFrameConfigType()</p>
240</td>
241<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p1993817744915"><a name="p1993817744915"></a><a name="p1993817744915"></a>Obtains the frame configuration type.</p>
242</td>
243</tr>
244<tr id="row793817784912"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p69381724914"><a name="p69381724914"></a><a name="p69381724914"></a>FrameConfig</p>
245</td>
246<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p149382077496"><a name="p149382077496"></a><a name="p149382077496"></a>std::list&lt;OHOS::Surface&gt; GetSurfaces()</p>
247</td>
248<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p893867114919"><a name="p893867114919"></a><a name="p893867114919"></a>Obtains a list of surface objects (shared memories).</p>
249</td>
250</tr>
251<tr id="row109401570498"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p294019712492"><a name="p294019712492"></a><a name="p294019712492"></a>FrameConfig</p>
252</td>
253<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p19940170499"><a name="p19940170499"></a><a name="p19940170499"></a>void AddSurface(OHOS::AGP::UISurface&amp; surface);</p>
254</td>
255<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p11940197144915"><a name="p11940197144915"></a><a name="p11940197144915"></a>Adds a surface.</p>
256</td>
257</tr>
258<tr id="row994018711492"><td class="cellrowborder" valign="top" width="18.811881188118814%" headers="mcps1.2.4.1.1 "><p id="p1094016718493"><a name="p1094016718493"></a><a name="p1094016718493"></a>FrameConfig</p>
259</td>
260<td class="cellrowborder" valign="top" width="46.534653465346544%" headers="mcps1.2.4.1.2 "><p id="p139411279498"><a name="p139411279498"></a><a name="p139411279498"></a>void RemoveSurface(OHOS::AGP::UISurface&amp; surface);</p>
261</td>
262<td class="cellrowborder" valign="top" width="34.65346534653466%" headers="mcps1.2.4.1.3 "><p id="p39415717494"><a name="p39415717494"></a><a name="p39415717494"></a>Removes a surface.</p>
263</td>
264</tr>
265<tr id="row994018711493"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="p1094016718493"><a name="p1094016718493"></a><a name="p1094016718493"></a>FrameConfig</p>
266</td>
267<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="p139411279498"><a name="p139411279498"></a><a name="p139411279498"></a>void GetVendorParameter(uint8_t *value, uint32_t len);</p>
268</td>
269<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="p39415717494"><a name="p39415717494"></a><a name="p39415717494"></a>Gets a vendor parameter.</p>
270</td>
271</tr>
272<tr id="row994018711494"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="p1094016718493"><a name="p1094016718493"></a><a name="p1094016718493"></a>FrameConfig</p>
273</td>
274<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="p139411279498"><a name="p139411279498"></a><a name="p139411279498"></a>void SetVendorParameter(uint8_t *value, uint32_t len);</p>
275</td>
276<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="p39415717494"><a name="p39415717494"></a><a name="p39415717494"></a>Sets a vendor parameter.</p>
277</td>
278</tr>
279<tr id="row994018711495"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="p1094016718493"><a name="p1094016718493"></a><a name="p1094016718493"></a>CameraInfo</p>
280</td>
281<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="p139411279498"><a name="p139411279498"></a><a name="p139411279498"></a>int32_t GetCameraType() const;</p>
282</td>
283<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="p39415717494"><a name="p39415717494"></a><a name="p39415717494"></a>Gets a camera type.</p>
284</td>
285</tr>
286<tr id="row994018711496"><td class="cellrowborder" valign="top" width="14.93%" headers="mcps1.2.4.1.1 "><p id="p1094016718493"><a name="p1094016718493"></a><a name="p1094016718493"></a>CameraInfo</p>
287</td>
288<td class="cellrowborder" valign="top" width="61.660000000000004%" headers="mcps1.2.4.1.2 "><p id="p139411279498"><a name="p139411279498"></a><a name="p139411279498"></a>int32_t GetCameraFacingType() const;</p>
289</td>
290<td class="cellrowborder" valign="top" width="23.41%" headers="mcps1.2.4.1.3 "><p id="p39415717494"><a name="p39415717494"></a><a name="p39415717494"></a>Gets a camera facing type.</p>
291</td>
292</tr>
293</tbody>
294</table>
295
296## Limitations and Constraints<a name="section1165911177314"></a>
297
298None
299
300## How to Develop<a name="section138543918214"></a>
301
3021.  <a name="li378084192111"></a>Extend the  **CameraDeviceCallback**  class and call  **OnCameraStatus**  to customize operations when the camera device changes, for example, when a camera becomes available or unavailable.
303
304    ```
305    class SampleCameraDeviceCallback : public CameraDeviceCallback {
306        void OnCameraStatus(std::string cameraId, int32_t status) override
307        {
308            // Do something when camera is available or unavailable.
309        }
310    };
311    ```
312
3132.  <a name="li8716104682913"></a>Extend the  **FrameStateCallback**  class. After obtaining the frame data, save the data as a file.
314
315    ```
316    static void SampleSaveCapture(const char *p, uint32_t size)
317    {
318        cout << "Start saving picture" << endl;
319        struct timeval tv;
320        gettimeofday(&tv, NULL);
321        struct tm *ltm = localtime(&tv.tv_sec);
322        if (ltm != nullptr) {
323            ostringstream ss("Capture_");
324            ss << "Capture" << ltm->tm_hour << "-" << ltm->tm_min << "-" << ltm->tm_sec << ".jpg";
325
326            ofstream pic("/sdcard/" + ss.str(), ofstream::out | ofstream::trunc);
327            cout << "write " << size << " bytes" << endl;
328            pic.write(p, size);
329            cout << "Saving picture end" << endl;
330        }
331    }
332
333    class TestFrameStateCallback : public FrameStateCallback {
334        void OnFrameFinished(Camera &camera, FrameConfig &fc, FrameResult &result) override
335        {
336            cout << "Receive frame complete inform." << endl;
337            if (fc.GetFrameConfigType() == FRAME_CONFIG_CAPTURE) {
338                cout << "Capture frame received." << endl;
339                list<Surface *> surfaceList = fc.GetSurfaces();
340                for (Surface *surface : surfaceList) {
341                    SurfaceBuffer *buffer = surface->AcquireBuffer();
342                    if (buffer != nullptr) {
343                        char *virtAddr = static_cast<char *>(buffer->GetVirAddr());
344                        if (virtAddr != nullptr) {
345                            SampleSaveCapture(virtAddr, buffer->GetSize());
346                        }
347                        surface->ReleaseBuffer(buffer);
348                    }
349                    delete surface;
350                }
351                delete &fc;
352            }
353        }
354    };
355    ```
356
3573.  <a name="li6671035102514"></a>Extend the  **CameraStateCallback**  class and customize operations when the camera state changes \(configuration successful or failed, and creation successful or failed\).
358
359    ```
360    class SampleCameraStateMng : public CameraStateCallback {
361    public:
362        SampleCameraStateMng() = delete;
363        SampleCameraStateMng(EventHandler &eventHdlr) : eventHdlr_(eventHdlr) {}
364        ~SampleCameraStateMng()
365        {
366            if (recordFd_ != -1) {
367                close(recordFd_);
368            }
369        }
370        void OnCreated(Camera &c) override
371        {
372            cout << "Sample recv OnCreate camera." << endl;
373            auto config = CameraConfig::CreateCameraConfig();
374            config->SetFrameStateCallback(&fsCb_, &eventHdlr_);
375            c.Configure(*config);
376            cam_ = &c;
377        }
378        void OnCreateFailed(const std::string cameraId, int32_t errorCode) override {}
379        void OnReleased(Camera &c) override {}
380    };
381    ```
382
3834.  Create a  **CameraKit**  instance to set and obtain camera information.
384
385    ```
386    CameraKit *camKit = CameraKit::GetInstance();
387    list<string> camList = camKit->GetCameraIds();
388    string camId;
389    for (auto &cam : camList) {
390        cout << "camera name:" << cam << endl;
391        const CameraAbility *ability = camKit->GetCameraAbility(cam);
392        /* Find the camera that fits your ability. */
393        list<CameraPicSize> sizeList = ability->GetSupportedSizes(0);
394        if (find(sizeList.begin(), sizeList.end(), CAM_PIC_1080P) != sizeList.end()) {
395            camId = cam;
396            break;
397        }
398    }
399    ```
400
4015.  Create a  **Camera**  instance.
402
403    ```
404    EventHandler eventHdlr; // Create a thread to handle callback events.
405    SampleCameraStateMng CamStateMng(eventHdlr);
406
407    camKit->CreateCamera(camId, CamStateMng, eventHdlr);
408    ```
409
4106.  In the main process, synchronize configurations set by callback functions implemented in  [step 1](#li378084192111),  [step 2](#li8716104682913), and  [step 3](#li6671035102514).
411
412    ```
413    void OnCreated(Camera &c) override
414    {
415        cout << "Sample recv OnCreate camera." << endl;
416        auto config = CameraConfig::CreateCameraConfig();
417        config->SetFrameStateCallback(&fsCb_, &eventHdlr_);
418        c.Configure(*config);
419        cam_ = &c;
420    }
421
422    void Capture()
423    {
424        if (cam_ == nullptr) {
425            cout << "Camera is not ready." << endl;
426            return;
427        }
428        FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE);
429        Surface *surface = Surface::CreateSurface();
430        if (surface == nullptr) {
431            delete fc;
432            return;
433        }
434        surface->SetWidthAndHeight(1920, 1080); /* 1920:width,1080:height */
435        fc->AddSurface(*surface);
436        cam_->TriggerSingleCapture(*fc);
437    }
438    ```
439
440
441