【问题标题】:Ionic/Cordova. Save image to photo gallery离子/科尔多瓦。将图像保存到照片库
【发布时间】:2015-12-08 21:06:41
【问题描述】:

我有一个指向外部 PNG 图像的 URL。我想将它直接下载到相机胶卷 (iOS) 或相册 (Android)。我如何使用 Ionic 管理它

【问题讨论】:

  • 您找到解决方案了吗?我正在寻找完全相同的解决方案,但没有找到。
  • 是的。 Canvas2Image 插件。

标签: angularjs cordova ionic-framework ionic cordova-plugins


【解决方案1】:

试试这个:

cordova plugin add org.apache.cordova.file-transfer

cordova plugin add cordova-plugin-file

在索引中添加文件链接。

 <script src="js/ng-cordova.js"></script>
 <script src="js/FileTransferController.js"></script>

在控制器中:

$scope.downloadFile = function() {
        var url = "http://your_ip_address/images/my.png";
        var filename = url.split("/").pop();
        alert(filename);
        var targetPath = cordova.file.externalRootDirectory + filename;
        var trustHosts = true
        var options = {};
        alert(cordova.file.externalRootDirectory);
        $cordovaFileTransfer.download(url, targetPath, options, trustHosts)
            .then(function(result) {
                // Success!
                alert(JSON.stringify(result));
            }, function(error) {
                // Error
                alert(JSON.stringify(error));
            }, function (progress) {
                $timeout(function () {
                    $scope.downloadProgress = (progress.loaded / progress.total) * 100;
                })
            });
    }

来自HERE

希望它对某人有所帮助。

【讨论】:

  • 它会下载到应用程序的文件系统还是相机胶卷?
  • 此代码将 inages 存储在应用程序内部的内部存储中
  • 是否可以将图像存储到相机胶卷中?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-03
  • 2015-03-30
  • 2016-08-30
  • 1970-01-01
  • 2020-09-10
  • 1970-01-01
相关资源
最近更新 更多