From da78a9e329e272dedb2400b79a3bdeebff387d47 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:17 -0500 Subject: initial commit --- files/ko/archive/b2g_os/api/camera_api/index.html | 38 ++++ .../b2g_os/api/camera_api/introduction/index.html | 247 +++++++++++++++++++++ 2 files changed, 285 insertions(+) create mode 100644 files/ko/archive/b2g_os/api/camera_api/index.html create mode 100644 files/ko/archive/b2g_os/api/camera_api/introduction/index.html (limited to 'files/ko/archive/b2g_os/api/camera_api') diff --git a/files/ko/archive/b2g_os/api/camera_api/index.html b/files/ko/archive/b2g_os/api/camera_api/index.html new file mode 100644 index 0000000000..d18716974b --- /dev/null +++ b/files/ko/archive/b2g_os/api/camera_api/index.html @@ -0,0 +1,38 @@ +--- +title: Camera API +slug: Archive/B2G_OS/API/Camera_API +tags: + - API + - Firefox OS + - Graphics + - NeedsTranslation + - Reference + - Référence(2) + - TopicStub + - WebAPI + - camera +translation_of: Archive/B2G_OS/API/Camera_API +--- +

+ +

+

Non-standard
+ This feature is not on a current W3C standards track, but it is supported on the Firefox OS platform. Although implementations may change in the future and it is not supported widely across browsers, it is suitable for use in code dedicated to Firefox OS apps.

+

+ +

The Camera API allows applications to manage the camera of the device. It allows them to take photographs, record videos, and get information like the focus, the zoom, the white balance, the flash, … It is a priviledged API and can only be used by certified applications.

+ +

This API was initially only available to certified applications, but is available to privileged apps on Firefox 2.0 onwards.

+ +
+

Note: Except if you are implementing a replacement for the default Camera application, you shouldn't use this API. Instead, if you want to use the camera in your device, you should use the Web Activities API.

+
+ +

See also

+ + diff --git a/files/ko/archive/b2g_os/api/camera_api/introduction/index.html b/files/ko/archive/b2g_os/api/camera_api/introduction/index.html new file mode 100644 index 0000000000..1ea6d25a38 --- /dev/null +++ b/files/ko/archive/b2g_os/api/camera_api/introduction/index.html @@ -0,0 +1,247 @@ +--- +title: Introduction to the Camera API +slug: Archive/B2G_OS/API/Camera_API/Introduction +translation_of: Archive/B2G_OS/API/Camera_API/Introduction +--- +

+ +

Camera API 를 사용하면 디바이스의 카메라를 이용해 사진을 찍어 현재 웹페이지에 업로드하는것이 가능해집니다. This is achieved through an input element with type="file" and an accept attribute to declare that it accepts images. The HTML looks like this:

+ +
<input type="file" id="take-picture" accept="image/*">
+
+ +

When users choose to activate this HTML element, they are presented with an option to choose a file, where the device's camera is one of the options. If they select the camera, it goes into picture taking mode. After the picture has been taken, the user is presented with a choice to accept or discard it. If accepted, it gets sent to the <input type="file"> element and its onchange event is triggered.

+ +

Get a reference to the taken picture

+ +

With the help of the File API you can then access the taken picture or chosen file:

+ +
var takePicture = document.querySelector("#take-picture");
+takePicture.onchange = function (event) {
+    // Get a reference to the taken picture or chosen file
+    var files = event.target.files,
+        file;
+    if (files && files.length > 0) {
+        file = files[0];
+    }
+};
+
+ +

Presenting the picture in the web page

+ +

Once you have a reference to the taken picture (i.e., file), you can then use window.URL.createObjectURL() to create a URL referencing the picture and setting it as the src of an image:

+ +
// Image reference
+var showPicture = document.querySelector("#show-picture");
+
+// Create ObjectURL
+var imgURL = window.URL.createObjectURL(file);
+
+// Set img src to ObjectURL
+showPicture.src = imgURL;
+
+// For performance reasons, revoke used ObjectURLs
+URL.revokeObjectURL(imgURL);
+
+ +

If createObjectURL() isn't supported, an alternative is to fallback to FileReader:

+ +
// Fallback if createObjectURL is not supported
+var fileReader = new FileReader();
+fileReader.onload = function (event) {
+    showPicture.src = event.target.result;
+};
+fileReader.readAsDataURL(file);
+
+ +

Complete example

+ +

If you want to see it in action, take a look at the complete working Camera API example.

+ +

Here is the code used for that demo:

+ +

HTML page

+ +
<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <title>Camera API</title>
+        <link rel="stylesheet" href="css/base.css" type="text/css" media="screen">
+    </head>
+
+    <body>
+
+        <div class="container">
+            <h1>Camera API</h1>
+
+            <section class="main-content">
+                <p>A demo of the Camera API, currently implemented in Firefox and Google Chrome on Android. Choose to take a picture with your device's camera and a preview will be shown through createObjectURL or a FileReader object (choosing local files supported too).</p>
+
+                <p>
+                    <input type="file" id="take-picture" accept="image/*">
+                </p>
+
+                <h2>Preview:</h2>
+                <p>
+                    <img src="about:blank" alt="" id="show-picture">
+                </p>
+
+                <p id="error"></p>
+
+            </section>
+
+            <p class="footer">All the code is available in the <a href="https://github.com/robnyman/robnyman.github.com/tree/master/camera-api">Camera API repository on GitHub</a>.</p>
+        </div>
+
+
+        <script src="js/base.js"></script>
+
+
+    </body>
+</html>
+
+ +

JavaScript file

+ +
(function () {
+    var takePicture = document.querySelector("#take-picture"),
+        showPicture = document.querySelector("#show-picture");
+
+    if (takePicture && showPicture) {
+        // Set events
+        takePicture.onchange = function (event) {
+            // Get a reference to the taken picture or chosen file
+            var files = event.target.files,
+                file;
+            if (files && files.length > 0) {
+                file = files[0];
+                try {
+                    // Create ObjectURL
+                    var imgURL = window.URL.createObjectURL(file);
+
+                    // Set img src to ObjectURL
+                    showPicture.src = imgURL;
+
+                    // Revoke ObjectURL
+                    URL.revokeObjectURL(imgURL);
+                }
+                catch (e) {
+                    try {
+                        // Fallback if createObjectURL is not supported
+                        var fileReader = new FileReader();
+                        fileReader.onload = function (event) {
+                            showPicture.src = event.target.result;
+                        };
+                        fileReader.readAsDataURL(file);
+                    }
+                    catch (e) {
+                        //
+                        var error = document.querySelector("#error");
+                        if (error) {
+                            error.innerHTML = "Neither createObjectURL or FileReader are supported";
+                        }
+                    }
+                }
+            }
+        };
+    }
+})();
+
+ +

Browser compatibility

+ +

We're converting our compatibility data into a machine-readable JSON format. + This compatibility table still uses the old format, + because we haven't yet converted the data it contains. + Find out how you can help!

+ +
+ + +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Camera APINo supportNo supportNo supportNo supportNo support
createObjectURL()168.0 (8.0)10No supportNo support
FileReader163.6 (1.9.2)1011.6No support
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Camera API3.0(Yes)10.0 (10.0)No supportNo supportNo support
createObjectURL()4(Yes)10.0 (10.0)No supportNo supportNo support
FileReader3(Yes)10.0 (10.0)No support11.10No support
+
-- cgit v1.2.3-54-g00ecf