arnaucube
arnaucube/openEventsPlatformAppPublic Self-hosted repository
openEventsPlatformApp/plugins/cordova-plugin-camera/doc/zh/README.md
plugins/cordova-plugin-camera/doc/zh/README.mdRaw
  1<!---
  2# license: Licensed to the Apache Software Foundation (ASF) under one
  3#         or more contributor license agreements.  See the NOTICE file
  4#         distributed with this work for additional information
  5#         regarding copyright ownership.  The ASF licenses this file
  6#         to you under the Apache License, Version 2.0 (the
  7#         "License"); you may not use this file except in compliance
  8#         with the License.  You may obtain a copy of the License at
  9#
 10#           http://www.apache.org/licenses/LICENSE-2.0
 11#
 12#         Unless required by applicable law or agreed to in writing,
 13#         software distributed under the License is distributed on an
 14#         "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15#         KIND, either express or implied.  See the License for the
 16#         specific language governing permissions and limitations
 17#         under the License.
 18-->
 19
 20# cordova-plugin-camera
 21
 22[![Build Status](https://travis-ci.org/apache/cordova-plugin-camera.svg)](https://travis-ci.org/apache/cordova-plugin-camera)
 23
 24這個外掛程式定義了一個全球 `navigator.camera` 物件,它提供了 API,拍照,從系統的圖像庫中選擇圖像。
 25
 26雖然該物件附加到全球範圍內 `導航器`,它不可用直到 `deviceready` 事件之後。
 27
 28    document.addEventListener("deviceready", onDeviceReady, false);
 29    function onDeviceReady() {
 30        console.log(navigator.camera);
 31    }
 32    
 33
 34## 安裝
 35
 36    cordova plugin add cordova-plugin-camera
 37    
 38
 39## API
 40
 41  * 相機 
 42      * navigator.camera.getPicture(success, fail, options)
 43      * CameraOptions
 44      * CameraPopoverHandle
 45      * CameraPopoverOptions
 46      * navigator.camera.cleanup
 47
 48## navigator.camera.getPicture
 49
 50需要一張照片,使用相機,或從設備的圖像庫檢索一張照片。 圖像被傳遞給成功回檔的 base64 編碼 `String`,或作為 URI 為影像檔。 該方法本身返回一個 `CameraPopoverHandle` 物件,它可以用來重新置放檔選擇氣泡框。
 51
 52    navigator.camera.getPicture(cameraSuccess, cameraError, cameraOptions);
 53    
 54
 55#### 說明
 56
 57`camera.getPicture` 函數打開該設備的預設攝像頭應用程式,允許使用者拍照。 `Camera.sourceType` 等於 `Camera.PictureSourceType.CAMERA` 時,預設情況下,發生此行為。 一旦使用者打斷了他的照片,相機應用程式關閉,且應用程式還原。
 58
 59如果 `Camera.sourceType` 是 `Camera.PictureSourceType.PHOTOLIBRARY` 或 `Camera.PictureSourceType.SAVEDPHOTOALBUM`,然後顯示一個對話方塊,允許使用者選擇一個現有的圖像。 `camera.getPicture` 函數返回一個 `CameraPopoverHandle` 物件,它可以用於重新置放圖像選擇的對話方塊,例如,當設備的方向變化。
 60
 61傳回值是發送到 `cameraSuccess` 回呼函數中,在以下的格式,具體取決於指定的 `cameraOptions` 之一:
 62
 63  * A `String` 包含的 base64 編碼的照片圖像。
 64
 65  * A `String` 表示在本機存放區 (預設值) 上的影像檔位置。
 66
 67你可以做任何你想要的編碼的圖像或 URI,例如:
 68
 69  * 呈現在圖像 `<img>` 標記,如下面的示例所示
 70
 71  * 保存本地的資料 ( `LocalStorage` , [Lawnchair](http://brianleroux.github.com/lawnchair/),等等.)
 72
 73  * 將資料發佈到遠端伺服器
 74
 75**注**: 在更新設備上的照片解析度是很好。 選擇從設備的庫的照片是不壓縮螢幕使其以較低的品質,即使指定了一個 `quality` 參數。 要避免常見的記憶體問題,請將 `Camera.destinationType` 設置為 `FILE_URI`,而不是 `DATA_URL`.
 76
 77#### 支援的平臺
 78
 79![](doc/img/android-success.png) ![](doc/img/blackberry-success.png) ![](doc/img/browser-success.png) ![](doc/img/firefox-success.png) ![](doc/img/fireos-success.png) ![](doc/img/ios-success.png) ![](doc/img/windows-success.png) ![](doc/img/wp8-success.png) ![](doc/img/ubuntu-success.png)
 80
 81#### 示例
 82
 83拍一張照片,並檢索它作為一個 base64 編碼的圖像:
 84
 85    navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
 86        destinationType: Camera.DestinationType.DATA_URL
 87    });
 88    
 89    function onSuccess(imageData) {
 90        var image = document.getElementById('myImage');
 91        image.src = "data:image/jpeg;base64," + imageData;
 92    }
 93    
 94    function onFail(message) {
 95        alert('Failed because: ' + message);
 96    }
 97    
 98
 99拍一張照片和檢索圖像的檔位置:
100
101    navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
102        destinationType: Camera.DestinationType.FILE_URI });
103    
104    function onSuccess(imageURI) {
105        var image = document.getElementById('myImage');
106        image.src = imageURI;
107    }
108    
109    function onFail(message) {
110        alert('Failed because: ' + message);
111    }
112    
113
114#### 首選項 (iOS)
115
116  * **CameraUsesGeolocation**(布林值,預設值為 false)。 用於捕獲 jpeg 檔,設置為 true,以在 EXIF 頭資訊中獲取地理定位資料。 這將觸發請求的地理位置的許可權,如果設置為 true。
117    
118        <preference name="CameraUsesGeolocation" value="false" />
119        
120
121#### 亞馬遜火 OS 怪癖
122
123亞馬遜火 OS 使用意圖啟動相機活動設備來捕捉圖像上, 和手機上記憶體不足,科爾多瓦活動可能被殺害。 在這種情況下,可能不會顯示圖像時恢復了科爾多瓦活動。
124
125#### Android 的怪癖
126
127Android 使用意圖以啟動相機活動設備來捕捉圖像上, 和手機上記憶體不足,科爾多瓦活動可能被殺害。 在這種情況下,可能不會顯示圖像時恢復了科爾多瓦活動。
128
129#### 瀏覽器的怪癖
130
131可以只返回照片作為 base64 編碼的圖像。
132
133#### 火狐瀏覽器作業系統的怪癖
134
135觀景窗外掛程式目前實施使用 [Web 活動](https://hacks.mozilla.org/2013/01/introducing-web-activities/).
136
137#### iOS 的怪癖
138
139包括 JavaScript `alert ()` 中的回呼函數會導致問題。 包裝內 `setTimeout()` 允許 iOS 圖像選取器或氣泡框以完全關閉之前,警報將顯示警報:
140
141    setTimeout(function() {
142        // do your thing here!
143    }, 0);
144    
145
146#### Windows Phone 7 的怪癖
147
148調用本機攝像頭應用程式,而通過 Zune 所連接的設備不能工作,並且觸發錯誤回檔。
149
150#### Tizen 怪癖
151
152泰只支援 `destinationType` 的 `Camera.DestinationType.FILE_URI` 和 `Camera.PictureSourceType.PHOTOLIBRARY` 的 `sourceType`.
153
154## CameraOptions
155
156要自訂相機設置的可選參數。
157
158    { quality : 75,
159      destinationType : Camera.DestinationType.DATA_URL,
160      sourceType : Camera.PictureSourceType.CAMERA,
161      allowEdit : true,
162      encodingType: Camera.EncodingType.JPEG,
163      targetWidth: 100,
164      targetHeight: 100,
165      popoverOptions: CameraPopoverOptions,
166      saveToPhotoAlbum: false };
167    
168
169  * **品質**: 保存的圖像,表示為範圍 0-100,100,是通常全解析度,無損失從檔案壓縮的品質。 預設值為 50。 *(人數)*(請注意相機的解析度有關的資訊是不可用)。
170
171  * **可**: 選擇傳回值的格式。預設值是 FILE_URI。定義在 `navigator.camera.DestinationType` *(人數)*
172    
173        Camera.DestinationType = {
174            DATA_URL : 0,      // Return image as base64-encoded string
175            FILE_URI : 1,      // Return image file URI
176            NATIVE_URI : 2     // Return image native URI (e.g., assets-library:// on iOS or content:// on Android)
177        };
178        
179
180  * **時**: 設置圖片的來源。預設值是觀景窗。定義在 `navigator.camera.PictureSourceType` *(人數)*
181    
182        Camera.PictureSourceType = {
183            PHOTOLIBRARY : 0,
184            CAMERA : 1,
185            SAVEDPHOTOALBUM : 2
186        };
187        
188
189  * **allowEdit**: 允許簡單編輯前選擇圖像。*(布林)*
190
191  * **encodingType**: 選擇返回的影像檔的編碼。預設值為 JPEG。定義在 `navigator.camera.EncodingType` *(人數)*
192    
193        Camera.EncodingType = {
194            JPEG : 0,               // Return JPEG encoded image
195            PNG : 1                 // Return PNG encoded image
196        };
197        
198
199  * **targetWidth**: 向尺度圖像的圖元寬度。必須用**targetHeight**。縱橫比保持不變。*(人數)*
200
201  * **targetHeight**: 以圖元為單位向尺度圖像的高度。必須用**targetWidth**。縱橫比保持不變。*(人數)*
202
203  * **媒體類型**: 設置的媒體,從選擇類型。 時才起作用 `PictureSourceType` 是 `PHOTOLIBRARY` 或 `SAVEDPHOTOALBUM` 。 定義在 `nagivator.camera.MediaType` *(人數)*
204    
205        Camera.MediaType = {
206            PICTURE: 0,    // allow selection of still pictures only. 預設情況。 Will return format specified via DestinationType
207            VIDEO: 1,      // allow selection of video only, WILL ALWAYS RETURN FILE_URI
208            ALLMEDIA : 2   // allow selection from all media types
209        };
210        
211
212  * **correctOrientation**: 旋轉圖像,該設備時捕獲的定向的正確。*(布林)*
213
214  * **saveToPhotoAlbum**: 將圖像保存到相冊在設備上捕獲後。*(布林)*
215
216  * **popoverOptions**: 只有 iOS 在 iPad 中指定氣泡框位置的選項。在中定義`CameraPopoverOptions`.
217
218  * **cameraDirection**: 選擇相機以使用 (前面或後面-面向)。預設值是背。定義在 `navigator.camera.Direction` *(人數)*
219    
220        Camera.Direction = {
221            BACK : 0,      // Use the back-facing camera
222            FRONT : 1      // Use the front-facing camera
223        };
224        
225
226#### 亞馬遜火 OS 怪癖
227
228  * 任何 `cameraDirection` 值回朝的照片中的結果。
229
230  * 忽略 `allowEdit` 參數。
231
232  * `Camera.PictureSourceType.PHOTOLIBRARY`和 `Camera.PictureSourceType.SAVEDPHOTOALBUM` 都顯示相同的相冊。
233
234#### Android 的怪癖
235
236  * 任何 `cameraDirection` 值回朝的照片中的結果。
237
238  * 安卓也用於作物活動 allowEdit,即使作物應工作,實際上將裁剪的圖像傳回給科爾多瓦,那個唯一的作品一直是一個與谷歌加上照片應用程式捆綁在一起。 其他作物可能無法工作。
239
240  * `Camera.PictureSourceType.PHOTOLIBRARY`和 `Camera.PictureSourceType.SAVEDPHOTOALBUM` 都顯示相同的相冊。
241
242#### 黑莓 10 怪癖
243
244  * 忽略 `quality` 參數。
245
246  * 忽略 `allowEdit` 參數。
247
248  * `Camera.MediaType`不受支援。
249
250  * 忽略 `correctOrientation` 參數。
251
252  * 忽略 `cameraDirection` 參數。
253
254#### 火狐瀏覽器作業系統的怪癖
255
256  * 忽略 `quality` 參數。
257
258  * `Camera.DestinationType`將被忽略並且等於 `1` (影像檔的 URI)
259
260  * 忽略 `allowEdit` 參數。
261
262  * 忽略 `PictureSourceType` 參數 (使用者選擇它在對話方塊視窗中)
263
264  * 忽略`encodingType`
265
266  * 忽略了 `targetWidth` 和`targetHeight`
267
268  * `Camera.MediaType`不受支援。
269
270  * 忽略 `correctOrientation` 參數。
271
272  * 忽略 `cameraDirection` 參數。
273
274#### iOS 的怪癖
275
276  * 設置 `quality` 低於 50,避免在某些設備上的記憶體不足錯誤。
277
278  * 當使用 `destinationType.FILE_URI` ,照片都保存在應用程式的臨時目錄。應用程式結束時,將刪除該應用程式的臨時目錄中的內容。
279
280#### Tizen 怪癖
281
282  * 不支援的選項
283
284  * 總是返回一個檔的 URI
285
286#### Windows Phone 7 和 8 怪癖
287
288  * 忽略 `allowEdit` 參數。
289
290  * 忽略 `correctOrientation` 參數。
291
292  * 忽略 `cameraDirection` 參數。
293
294  * 忽略 `saveToPhotoAlbum` 參數。 重要: 使用 wp7/8 科爾多瓦攝像頭 API 拍攝的所有圖像總是都複製到手機的相機膠捲。 根據使用者的設置,這可能也意味著圖像是自動上傳到他們另。 這有可能意味著的圖像,可以比你的應用程式的目的更多的觀眾。 如果此阻滯劑您的應用程式,您將需要實現 CameraCaptureTask 在 msdn 上記載: [HTTP://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394006.aspx](http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394006.aspx)你可能還評論或在[問題追蹤器](https://issues.apache.org/jira/browse/CB-2083)的向上投票的相關的問題
295
296  * 忽略了 `mediaType` 屬性的 `cameraOptions` 作為 Windows Phone SDK 並不提供從 PHOTOLIBRARY 中選擇視頻的方法。
297
298## CameraError
299
300onError 的回呼函數提供了一條錯誤訊息。
301
302    function(message) {
303        // Show a helpful message
304    }
305    
306
307#### 說明
308
309  * **message**: 消息提供的設備的本機代碼。*(String)*
310
311## cameraSuccess
312
313提供的圖像資料的 onSuccess 回呼函數。
314
315    function(imageData) {
316        // Do something with the image
317    }
318    
319
320#### 說明
321
322  * **imageData**: Base64 編碼進行編碼的圖像資料,*或*影像檔的 URI,取決於 `cameraOptions` 效果。*(String)*
323
324#### 示例
325
326    // Show image
327    //
328    function cameraCallback(imageData) {
329        var image = document.getElementById('myImage');
330        image.src = "data:image/jpeg;base64," + imageData;
331    }
332    
333
334## CameraPopoverHandle
335
336由 `navigator.camera.getPicture` 創建的氣泡框對話方塊的控制碼.
337
338#### 說明
339
340  * **setPosition**: Set the position of the popover. Takes the `CameraPopoverOptions` that specify the new position.
341
342#### 支援的平臺
343
344![](doc/img/android-fail.png) ![](doc/img/blackberry-fail.png) ![](doc/img/browser-fail.png) ![](doc/img/firefox-fail.png) ![](doc/img/fireos-fail.png) ![](doc/img/ios-success.png) ![](doc/img/windows-fail.png) ![](doc/img/wp8-fail.png) ![](doc/img/ubuntu-fail.png)
345
346#### 示例
347
348     var cameraPopoverHandle = navigator.camera.getPicture(onSuccess, onFail,
349         { destinationType: Camera.DestinationType.FILE_URI,
350           sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
351           popoverOptions: new CameraPopoverOptions(300, 300, 100, 100, Camera.PopoverArrowDirection.ARROW_ANY)
352         });
353    
354     // Reposition the popover if the orientation changes.
355     window.onorientationchange = function() {
356         var cameraPopoverOptions = new CameraPopoverOptions(0, 0, 100, 100, Camera.PopoverArrowDirection.ARROW_ANY);
357         cameraPopoverHandle.setPosition(cameraPopoverOptions);
358     }
359    
360
361## CameraPopoverOptions
362
363iOS 僅指定氣泡框的錨元素的位置和箭頭方向,從 iPad 庫或專輯選擇圖像時的參數。
364
365    { x : 0,
366      y :  32,
367      width : 320,
368      height : 480,
369      arrowDir : Camera.PopoverArrowDirection.ARROW_ANY
370    };
371    
372
373#### 說明
374
375  * **x**: x 螢幕元素到其錨定氣泡框上的圖元座標。*(人數)*
376
377  * **y**: 螢幕元素到其錨定氣泡框上的 y 圖元座標。*(人數)*
378
379  * **width**: 寬度以圖元為單位),到其錨定氣泡框上的螢幕元素。*(人數)*
380
381  * **height**: 高度以圖元為單位),到其錨定氣泡框上的螢幕元素。*(人數)*
382
383  * **arrowDir**: 氣泡框上的箭頭應指向的方向。定義在 `Camera.PopoverArrowDirection` *(人數)*
384    
385            Camera.PopoverArrowDirection = {
386                ARROW_UP : 1,        // matches iOS UIPopoverArrowDirection constants
387                ARROW_DOWN : 2,
388                ARROW_LEFT : 4,
389                ARROW_RIGHT : 8,
390                ARROW_ANY : 15
391            };
392        
393
394請注意氣泡框的大小可能會更改箭頭的方向和螢幕的方向進行調整。 請確保帳戶方向更改時指定錨元素位置。
395
396## navigator.camera.cleanup
397
398刪除中間從臨時存儲攝像機所拍攝的照片。
399
400    navigator.camera.cleanup( cameraSuccess, cameraError );
401    
402
403#### 說明
404
405刪除保留在臨時存儲在調用 `camera.getPicture` 後的中間的影像檔。 適用只有當 `Camera.sourceType` 的值等於 `Camera.PictureSourceType.CAMERA` 和 `Camera.destinationType` 等於 `Camera.DestinationType.FILE_URI`.
406
407#### 支援的平臺
408
409![](doc/img/android-fail.png) ![](doc/img/blackberry-fail.png) ![](doc/img/browser-fail.png) ![](doc/img/firefox-fail.png) ![](doc/img/fireos-fail.png) ![](doc/img/ios-success.png) ![](doc/img/windows-fail.png) ![](doc/img/wp8-fail.png) ![](doc/img/ubuntu-fail.png)
410
411#### 示例
412
413    navigator.camera.cleanup(onSuccess, onFail);
414    
415    function onSuccess() {
416        console.log("Camera cleanup success.")
417    }
418    
419    function onFail(message) {
420        alert('Failed because: ' + message);
421    }