2012-10-25 72 views
2

我是PhoneGap的新手,想知道如何在iOS中将照片保存到照片。通过PhoneGap在iOS中保存照片到PNG或JPG图像

虽然我能够使用

navigator.camera.getPicture 

与选项

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

保存用相机照片拍摄的照片,我现在正在试图找出如何保存在 - 应用图片转为照片。 “:; BASE64,图像/ JPEG数据” ...

<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其中元素myPhoto持有的图象 - 科尔多瓦页如 -

考虑下面的PhoneGap ()通过Phonegap将图像数据从myPhoto保存到iOS中的照片?

回答

2

我最近遇到下面的PhoneGap插件来为iOS中保存画布图像照片: https://github.com/devgeeks/Canvas2ImagePlugin

按照自述instructions导入插件,然后你可以使用它的方式如下:

<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> 
+0

我用你的代码和程序但我无法获得解决方案。你能帮我找出答案吗? –

+0

是的我得到解决方案..我得到了线程警告:插件应该使用CordovaInterface.getThreadPool()。 – Muthu

4

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

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

简短的例子:

document.addEventListener("deviceready",onDeviceReady); 

//google logo url 
url = 'https://www.google.com/images/srpr/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' 

你也可以保存在本地文件,图片库使用下载方法

+0

谢谢!!!这对我有效。我面临的唯一问题是,我在我的网址中有空间。反正,节省了我的时间:) – ishhhh

+1

@ishhhh嗨,你可能想编码你的网址:) – Nimbosa

+0

是的。我也是这样做的。谢谢:) – ishhhh

相关问题