1
|
cordova plugin add cordova-plugin-camera
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<!DOCTYPE html>
<html>
<head>
<title>Capture Photo</title>
<meta http-equiv=
"Content-type"
content=
"text/html; charset=utf-8"
>
<script type=
"text/javascript"
charset=
"utf-8"
src=
"cordova.js"
></script>
<script type=
"text/javascript"
charset=
"utf-8"
>
var
pictureSource;
var
destinationType;
document.addEventListener(
"deviceready"
,onDeviceReady,
false
);
//Cordova加載完成會觸發
function
onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
//獲取照片
function
getPhoto(source) {
//quality : 圖像的質量,範圍是[0,100]
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source });
}
//獲取照片成功
function
onPhotoURISuccess(imageURI) {
//打印出照片路徑
console.log(imageURI);
var
largeImage = document.getElementById(
'largeImage'
);
largeImage.style.display =
'block'
;
largeImage.src = imageURI;
}
//獲取照片是吧
function
onFail(message) {
alert(
'獲取失敗: '
+ message);
}
</script>
</head>
<body style=
"padding-top:50px"
>
<button style=
"font-size:23px;"
onclick=
"getPhoto(pictureSource.PHOTOLIBRARY);"
>
從「相簿」中獲取照片
</button> <br>
<img style=
"display:none;"
id=
"largeImage"
src=
""
/>
</body>
</html>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<!DOCTYPE html>
<html>
<head>
<title>Capture Photo</title>
<meta http-equiv=
"Content-type"
content=
"text/html; charset=utf-8"
>
<script type=
"text/javascript"
charset=
"utf-8"
src=
"cordova.js"
></script>
<script type=
"text/javascript"
charset=
"utf-8"
>
var
pictureSource;
var
destinationType;
document.addEventListener(
"deviceready"
,onDeviceReady,
false
);
//Cordova加載完成會觸發
function
onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
//獲取照片
function
getPhoto(source) {
//quality : 圖像的質量,範圍是[0,100]
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source });
}
//獲取照片成功
function
onPhotoURISuccess(imageURI) {
//打印出照片路徑
console.log(imageURI);
var
largeImage = document.getElementById(
'largeImage'
);
largeImage.style.display =
'block'
;
largeImage.src = imageURI;
}
//獲取照片是吧
function
onFail(message) {
alert(
'獲取失敗: '
+ message);
}
</script>
</head>
<body style=
"padding-top:50px"
>
<button style=
"font-size:23px;"
onclick=
"getPhoto(pictureSource.SAVEDPHOTOALBUM);"
>
從「時刻」中獲取照片
</button> <br>
<img style=
"display:none;"
id=
"largeImage"
src=
""
/>
</body>
</html>
|