我只想保存图片base64并在图库中打开它。我不想从画廊拍照或拍照。
<img src="base64" />
<button>Save</button>
phonegap + angularjs
谢谢!
答案 0 :(得分:2)
<强>解决方案:强>
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
var fileTransfer = new FileTransfer();
var uri = encodeURI("http://www.example.com/image");
var path = fileSystem.root.toURL() + "appName/example.jpg";
fileTransfer.download(
uri,
path,
function(entry) {
refreshMedia.refresh(path); // Refresh the image gallery
},
function(error) {
console.log(error.source);
console.log(error.target);
console.log(error.code);
},
false,
{
headers: {
"Authorization": "dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
}
}
);
});
我需要创建一个插件来刷新图库,因为当你在Android设备上保存图像时,这个图像不会出现在图库中。此插件会更新图库。
refreshMedia.refresh(path); // Refresh the image gallery
答案 1 :(得分:0)
CLI:cordova插件添加org.apache.cordova.camera
document.addEventListener("deviceready",onDeviceReady,false);
var pictureSource; // picture source
var destinationType; // sets the format of returned value
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
$(document).on('click','#pic_parse',function(){
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
encodingType: Camera.EncodingType.PNG,
destinationType: destinationType.DATA_URL,
sourceType: pictureSource.SAVEDPHOTOALBUM });
});
function onPhotoDataSuccess(imageData) {
alert(imageData);//here, imageDate is base64.Now, you can save base64.
}
function onFail(message) {
alert('Failed because: ' + message);
}
希望,它会帮助你!
答案 2 :(得分:0)
要在cordova上下载base64图像,请使用此插件,还将您的图像扫描到图库中。
https://github.com/agomezmoron/cordova-save-image-gallery
public final void removeByName( final String name )
{
for( var i = passengers.iterator(); i.hasNext(); )
{
if( passengerNameMatches( name, i.next() ) ) i.remove();
}
}