|
@@ -112,58 +112,42 @@ export default {
|
|
|
// let currUniPage = getCurrentPages()[getCurrentPages().length - 1].$vm;
|
|
|
//时机合适时-像素存在则触发生成
|
|
|
return new Promise(resolve => {
|
|
|
- if(type==3){
|
|
|
- this.getClipPicUrl(resolve)
|
|
|
- }else{
|
|
|
- this.screenPromiseShot().then((param) => {
|
|
|
- if(param){
|
|
|
- this.flip(param[0], param[1], param[2], 4);
|
|
|
- const canvas = this.canvas2d;
|
|
|
- const ctx = canvas.getContext('2d');
|
|
|
- // ImageData 对象,data是像素 一维数组,包含以 RGBA 顺序的数据,数据使用 0 至 255(包含)的整数表示
|
|
|
- const img = canvas.createImageData(param[0], param[1], param[2]);
|
|
|
- canvas.height = img.height;
|
|
|
- canvas.width = img.width;
|
|
|
- ctx.putImageData(img, 0, 0);
|
|
|
- uni.canvasToTempFilePath({
|
|
|
- x: 0,
|
|
|
- y: 0,
|
|
|
- destWidth: canvas.width,
|
|
|
- destHeight: canvas.height,
|
|
|
- canvasId: "canvas",
|
|
|
- canvas: canvas,
|
|
|
- fileType: 'jpg',
|
|
|
- quality: 1,
|
|
|
- success: (res)=> {
|
|
|
- console.log("***canvasToTempFilePath-success***", res)
|
|
|
- this.upload(res.tempFilePath,resolve);
|
|
|
- },
|
|
|
- fail: (res)=> {
|
|
|
- console.warn("***canvasToTempFilePath-fail***", res);
|
|
|
- if(this && this.starRender && typeof(this.starRender)=='function'){
|
|
|
- this.starRender()//启动渲染
|
|
|
- }
|
|
|
- resolve('')
|
|
|
- }
|
|
|
- })
|
|
|
- }else{
|
|
|
- // let imgBase64 = this.canvas.toDataURL();
|
|
|
- // this.base64src(imgBase64, (res) => {
|
|
|
- // console.warn('转化后的url:', res)
|
|
|
- // this.upload(res,resolve);
|
|
|
- // })
|
|
|
-
|
|
|
- // let img = new Image();
|
|
|
- // img.src = this.canvas.toDataURL('image/jpeg');// toDataURL :图片格式转成 base64
|
|
|
- let imgBase64 = this.canvas.toDataURL();
|
|
|
- if(type==2){
|
|
|
- resolve(imgBase64)
|
|
|
- }else if(type==1){
|
|
|
- this.uploadFile(imgBase64,resolve)
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
+ this.screenPromiseShot().then((param) => {
|
|
|
+ if(param){
|
|
|
+ let {pixelData,width,height} = param;
|
|
|
+ this.flip(pixelData,width,height, 4);
|
|
|
+ let canvas = document.getElementById('canvas');
|
|
|
+ let context = canvas.getContext('2d');
|
|
|
+
|
|
|
+ let img = context.createImageData(width, height);
|
|
|
+ for (var i = 0; i < img.data.length; i += 4) {
|
|
|
+ img.data[i + 0] = pixelData[i + 0];
|
|
|
+ img.data[i + 1] = pixelData[i + 1];
|
|
|
+ img.data[i + 2] = pixelData[i + 2];
|
|
|
+ img.data[i + 3] = pixelData[i + 3];
|
|
|
+ }
|
|
|
+ canvas.height = img.height;
|
|
|
+ canvas.width = img.width;
|
|
|
+ context.putImageData(img, 0, 0);
|
|
|
+ let imgBase64 = canvas.toDataURL();
|
|
|
+ this.uploadFile(imgBase64,resolve);
|
|
|
+ }else{
|
|
|
+ // let imgBase64 = this.canvas.toDataURL();
|
|
|
+ // this.base64src(imgBase64, (res) => {
|
|
|
+ // console.warn('转化后的url:', res)
|
|
|
+ // this.upload(res,resolve);
|
|
|
+ // })
|
|
|
+
|
|
|
+ // let img = new Image();
|
|
|
+ // img.src = this.canvas.toDataURL('image/jpeg');// toDataURL :图片格式转成 base64
|
|
|
+ let imgBase64 = this.canvas.toDataURL();
|
|
|
+ if(type==2){
|
|
|
+ resolve(imgBase64)
|
|
|
+ }else if(type==1){
|
|
|
+ this.uploadFile(imgBase64,resolve)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
})
|
|
|
},
|
|
|
async uploadFile(file, cb = null) {
|