2012-10-25 70 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

相關問題