gpt4 book ai didi

javascript - 捕获phonegap ios后保存图像

转载 作者:行者123 更新时间:2023-11-29 04:07:45 24 4
gpt4 key购买 nike

我正在使用phonegap开发iOS应用程序...我使用了默认的相机API,这样用户就可以为他的用户个人资料照片拍照。

该功能工作正常,但我的问题是用户捕获的图像不会保存在系统文件中,因此我可以在其他页面中检索它

这是我的代码

var pictureSource;   // picture source
var destinationType; // sets the format of returned value

// Wait for Cordova to connect with the device
//
document.addEventListener("deviceready",onDeviceReady,false);

// Cordova is ready to be used!
//
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}

// Called when a photo is successfully retrieved
//
function onPhotoDataSuccess(imageData) {
// Uncomment to view the base64 encoded image data
// console.log(imageData);

// Get image handle
//
var smallImage = document.getElementById('smallImage');

// Unhide image elements
//
smallImage.style.display = 'block';

// Show the captured photo
// The inline CSS rules are used to resize the image
//
smallImage.src = "data:image/jpeg;base64," + imageData;

}

// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageURI) {
// Uncomment to view the image file URI
// console.log(imageURI);

// Get image handle
//
document.getElementById('smallImage').src='img/me2.jpg';
var smallImage = 'img/me2.jpg';

// Unhide image elements
//
smallImage.style.display = 'block';

// Show the captured photo
// The inline CSS rules are used to resize the image
//
smallImage.src = imageURI;
}

// A button will call this function
//
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
destinationType: destinationType.DATA_URL });
}

// A button will call this function
//
function capturePhotoEdit() {
// Take picture using device camera, allow edit, and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, allowEdit: true,
destinationType: destinationType.DATA_URL });
}

// A button will call this function
//
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source });
}

// Called if something bad happens.
//
function onFail(message) {
alert('Failed because: ' + message);
}

用户使用相机拍照后如何覆盖文件(“img/me2.jpg”)?

最佳答案

您无法覆盖 img/me2.jpg,因为该文件位于应用程序包中。

您必须将捕获的图像保存在应用程序数据文件夹中(例如使用 PhoneGap 的文件 API),然后将 URL 保存在 localStorage 中,以便您可以随时检索它。

关于javascript - 捕获phonegap ios后保存图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14936943/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com