图片的上传
第一步弹出框进行选择头像的来源,是相机还是相册,和取消状态
var a = [{
title: “拍照”
}, {
title: “从手机相册选择”
}];
plus.nativeUI.actionSheet({
title: “上传头像”,
cancel: “取消”,
buttons: a
第二步对手机打开摄像头和相册进行申请操作打开
var c = plus.camera.getCamera();
c.captureImage(function(e) {
//存储到本地
plus.io.resolveLocalFileSystemURL(e, function(entry) {
cutImage(entry.toLocalURL());
}, function(e) {
console.log(“读取拍照文件错误:” + e.message);
});
plus.gallery.pick(function(a) {
plus.io.resolveLocalFileSystemURL(a, function(entry) { //entry为图片原目录(相册)的句柄
cutImage(entry.toLocalURL());
}, function(e) {
console.log(“读取图片错误:” + e.message);
});
第三步对于拍好或者选择好的图片进行选择喜欢部分进行截取操作
var img = document.getElementById(“im_exif”);
img.src = path;
img.addEventListener("load", function() {
//exif调整图片的横竖
EXIF.getData(this, function() {
var orientation = EXIF.getAllTags(this).Orientation;
$("#im").attr("src", loadcopyImg(img, orientation));
document.getElementById("cropper-example-1").classList.remove("mui-hidden"); //显示裁剪区域
cropperImg();
});
})var that = this;
var canvas = document.createElement("canvas");
var square = 500;
var imageWidth, imageHeight;
if (img.width > img.height) {
imageHeight = square;
imageWidth = Math.round(square * img.width / img.height);
} else {
imageHeight = square; //this.width;
imageWidth = Math.round(square * img.width / img.height);
}
canvas.height = imageHeight;
canvas.width = imageWidth;
if (opt == 6) {
that.num = 90;
} else if (opt == 3) {
that.num = 180;
} else if (opt == 8) {
that.num = 270;
}
if (that.num == 360) {
that.num = 0;
}
var ctx = canvas.getContext("2d");
ctx.translate(imageWidth / 2, imageHeight / 2);
ctx.rotate(that.num * Math.PI / 180);
ctx.translate(-imageWidth / 2, -imageHeight / 2);
ctx.drawImage(img, 0, 0, imageWidth, imageHeight);
var dataURL = canvas.toDataURL("image/jpeg", 1);
return dataURL;