您好,登錄后才能下訂單哦!
詳情鏈接地址:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/cordova-4-canvas2p_w_picpathplugin/
在前面幾篇文章中簡(jiǎn)單寫(xiě)了一下,在項(xiàng)目中怎么實(shí)現(xiàn)掃描的功能和將信息轉(zhuǎn)化為二維碼的功能,現(xiàn)在來(lái)介紹一下怎么將生成的二維碼保存到手機(jī)的本地,這樣關(guān)于二維碼的內(nèi)容基本上就全面了,好開(kāi)心~~!
同樣的,我還是想說(shuō),首先我這個(gè)是做基于ionic+ngCordova+Anjularjs的項(xiàng)目,所以,希望大家在看之前已經(jīng)了解了這三塊內(nèi)容了,不然,可能看起來(lái)會(huì)有難度的。
一、下載相關(guān)的插件的命令:
[javascript] view plain copy
cordova plugin add https://github.com/devgeeks/Canvas2ImagePlugin.git
二、HTML代碼:
[html] view plain copy
<div class="col text-center">
<span>(二維碼)</span>
<div class="cro">
<div id="Qrcode">
<div class="cro_left_top"></div>
<div class="cro_right_top"></div>
<div class="cro_left_bottom"></div>
<div class="cro_right_bottom"></div>
</div>
<button class="button button-positive"
ng-click="saveImageQrcode()">保存到手機(jī)
</button>
</div>
</div>
三、CSS代碼,根據(jù)UI實(shí)現(xiàn)了如下界面的CSS代碼:
[css] view plain copy
<style type="text/css">
.cro {
width: 300px;
height: 360px;
position: relative;
text-align: center;
margin: auto;
background: white;
}
.cro_left_top, .cro_right_top, .cro_left_bottom, .cro_right_bottom {
position: absolute;
width: 20px;
height: 20px;
z-index: 1;
background: #212A27;
}
.cro_left_top {
top: -1px;
left: -1px;
border-radius: 0px 0px 20px 0px;
}
.cro_right_top {
top: -1px;
right: -1px;
border-radius: 0px 0px 0px 20px;
}
.cro_left_bottom {
left: -1px;
bottom: -1px;
border-radius: 0px 20px 0px 0px;
}
.cro_right_bottom {
right: -1px;
bottom: -1px;
border-radius: 20px 0px 0px 0px;
}
</style>
四、JS代碼如下:
[javascript] view plain copy
var qrcode = new QRCode(document.getElementById("Qrcode"), {
width: 200,
height: 200
});
qrcode.makeCode("123");
var a = document.getElementById("Qrcode");
var canvas = a.children[4];
canvas.id = "myCanvas";
$scope.saveImage = canvas.toDataURL();
//調(diào)用保存二維碼圖片的函數(shù)
$scope.saveImageQrcode = function () {
console.log(window.canvas2ImagePlugin);
window.canvas2ImagePlugin.saveImageDataToLibrary(function (msg) {
console.log(msg);
$rootScope.alert('圖片已保存');
},
function (err) {
console.log(err);
},
document.getElementById('myCanvas')
)
};
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。