javascript PhoneGap - Android - 如何将相机的捕获图像保存在 SD 卡中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9926152/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PhoneGap - Android - how to save the capture image from camera in the sd card
提问by Preet_Android
I'm new in PhoneGap Android developer. I'm making an application in android using the phonegap. I want to take picture from the device camera and then i want to display it on the screen after taking the image from device and as well as store that captured image in the SD Card. Can you please tell me how i can do this.
我是 PhoneGap Android 开发人员的新手。我正在使用 phonegap 在 android 中创建一个应用程序。我想从设备相机拍摄照片,然后我想在从设备拍摄图像后将其显示在屏幕上,并将捕获的图像存储在 SD 卡中。你能告诉我我怎么能做到这一点。
Gurpreet singh
古尔普雷特·辛格
回答by dhaval
Refer the following gist which does capture the image from camera in both data and file mode.
请参阅以下以数据和文件模式从相机捕获图像的要点。
Reference from
参考自
回答by vikky
For saving in the SD card......
用于保存在 SD 卡中......
function save(){
document.addEventListener("deviceready", onDeviceReady, false);
}
// PhoneGap is ready
//
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
fileSystem.root.getFile("pic.jpg", {create: true, exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
var photo = document.getElementById("image");
writer.write(photo.value);
}
function fail(error) {
console.log(error.code);
}