Saving a PNG or JPG image to Photos in iOS via PhoneGap(通过 PhoneGap 将 PNG 或 JPG 图像保存到 iOS 中的照片)
问题描述
我是 PhoneGap 的新手,想知道如何将应用内图像保存到 iOS 中的照片.
I am new to PhoneGap and would like to know how to save an in-App image to Photos in iOS.
虽然我可以使用
navigator.camera.getPicture
有选项
quality:50, destinationType:Camera.DestinationType.DATA_URL,saveToPhotoAlbum: true
要将使用相机拍摄的照片保存到照片中,我现在正在尝试了解如何将应用内图像保存到照片中.
to save a picture taken with the camera to Photos, I am now trying to find out how to save an in-App image to Photos.
考虑以下 PhoneGap - Cordova 页面,其中元素 myPhoto 保存图像数据,例如data:image/jpeg;base64,"...
Consider the following PhoneGap - Cordova page where the element myPhoto holds imagedata such as "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 中的照片?
What should savePicture() do to save the imagedata from myPhoto to Photos in iOS via Phonegap?
推荐答案
我最近遇到了以下 Phonegap 插件,用于在 iOS 中将 Canvas 图像保存到照片:https://github.com/devgeeks/Canvas2ImagePlugin
I recently came across the following Phonegap plugin for saving Canvas images to Photos in iOS: https://github.com/devgeeks/Canvas2ImagePlugin
按照自述文件 instructions 导入插件,然后您就可以使用方法如下:
Follow the readme instructions for importing the plugin and then you can use it the following way:
<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>
这篇关于通过 PhoneGap 将 PNG 或 JPG 图像保存到 iOS 中的照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:通过 PhoneGap 将 PNG 或 JPG 图像保存到 iOS 中的照片
基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01