2

我是 PhoneGap 的新手,想知道如何将应用内图像保存到 iOS 中的照片。

虽然我能够使用

navigator.camera.getPicture

有选项

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

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

考虑以下 PhoneGap - Cordova 页面,其中元素 myPhoto 保存图像数据,例如“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() 应该如何通过 Phonegap 将 myPhoto 中的图像数据保存到 iOS 中的照片?

4

2 回答 2

4

也许你可以试试我为 IOS 编写的插件(如果你想将画布元素保存到相册,你可以使用下面的downloadWithUrl方法获取画布的 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'

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

于 2014-09-07T07:48:09.520 回答
2

我最近遇到了以下 Phonegap 插件,用于将 Canvas 图像保存到 iOS 中的照片: 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>
于 2012-10-27T20:10:00.850 回答