是不是图片还没加载完成
小程序调用拍照组件,偶尔出现黑图?bindTakePhoto() { const cameraContext = wx.createCameraContext(); const photoProp = { quality: 'high' }; cameraContext.takePhoto(photoProp) .then((res) => { this.drawPhoto(res.tempImagePath); }) .catch((error) => { logger.error(error) // console.log(error) }) }, /** * 画照片 */ async drawPhoto(filePath) { const ctx = this.canvas.getContext('2d') const dpr = app.globalData.screenHeight / app.globalData.rpxScreenHeight; const canvasWidth = this.data.canvasWidth * dpr; const canvasHeight = this.data.canvasHeight * dpr; //画照片 await new Promise((resolve) => { const photoImage = this.canvas.createImage() photoImage.onload = () => { const photoWidth = canvasWidth; const photoHeight = canvasHeight; const x = 0; const y = 0; const direction = this.data.direction; if (direction == 'left') { ctx.translate(0, photoHeight); ctx.rotate(-Math.PI / 2); ctx.drawImage(photoImage, x, y, photoHeight, photoWidth); ctx.rotate(Math.PI / 2); ctx.translate(0, -photoHeight); } else if (direction == 'right') { ctx.translate(photoWidth, 0); ctx.rotate(Math.PI / 2); ctx.drawImage(photoImage, x, y, photoHeight, photoWidth); ctx.rotate(-Math.PI / 2); ctx.translate(-photoWidth, 0); } else { ctx.drawImage(photoImage, x, y, photoWidth, photoHeight); } // console.log('已画照片'); resolve('已画照片') } photoImage.onerror = () => { // console.log('照片加载失败'); resolve(); } photoImage.src = filePath; }) //画现场水印 if (this.data.liveWatermark && this.data.liveWatermarkValue && this.data.liveWatermarkValue != '') { await new Promise((resolve) => { const liveWatermarkImage = this.canvas.createImage() liveWatermarkImage.onload = () => { const liveWatermarkWidth = dpr * 360; const liveWatermarkHeight = dpr * 90; const x = canvasWidth / 2 - liveWatermarkWidth / 2; const y = canvasHeight / 2 - liveWatermarkHeight / 2; ctx.drawImage(liveWatermarkImage, x, y, liveWatermarkWidth, liveWatermarkHeight); // console.log('已画现场水印', this.data.liveWatermarkValue); resolve('已画现场水印'); } liveWatermarkImage.onerror = () => { // console.log('现场水印加载失败', this.data.liveWatermarkValue); resolve(); } liveWatermarkImage.src = this.data.liveWatermarkValue; }) } //画手写签名水印 if (this.data.handWriting && this.data.handWriting != '') { await new Promise((resolve) => { const handWritingImage = this.canvas.createImage() handWritingImage.onload = () => { const handWritingWidth = dpr * 150; const handWritingHeight = dpr * 150; const x = canvasWidth - handWritingWidth - 10; const y = canvasHeight - 10; ctx.translate(x, y); ctx.rotate(-Math.PI / 2); ctx.drawImage(handWritingImage, 0, 0, handWritingWidth, handWritingHeight); ctx.rotate(Math.PI / 2); ctx.translate(-x, -y); // console.log('已画手写签名水印'); resolve('已画手写签名水印'); } handWritingImage.onerror = () => { // console.log('手写签名水印加载失败'); resolve(); } handWritingImage.src = this.data.handWriting; }) } //画水印LOGO if (this.data.logoEnable && this.data.logo && this.data.logo != '') { // console.log('画水印LOGO'); await new Promise((resolve) => { const logoImage = this.canvas.createImage() logoImage.onload = () => { const logoWidth = dpr * 150; const logoHeight = dpr * 150; const x = canvasWidth - logoWidth - 10; const y = 10; //水印LOGO透明度 const alpha = 1 - app.globalData.logoTransparency * 5 / 100; ctx.globalAlpha = alpha; ctx.drawImage(logoImage, x, y, logoWidth, logoHeight); ctx.globalAlpha = 1; // console.log('已画水印LOGO'); resolve('已画水印LOGO'); } logoImage.onerror = () => { // console.log('水印LOGO加载失败'); resolve(); } logoImage.src = this.data.logo; }) } // console.log('画水印信息'); //设置画笔 ctx.font = '14px'; ctx.fillStyle = this.data.watermarkFontColor; //颜色 const watermarkX = 10; const watermarkY = canvasHeight - 14; const lineHeight = 18; let i = 0; //备注 const remarkArr = this.data.remarkArr; if (remarkArr && remarkArr.length > 0) { for (let index = remarkArr.length - 1; index >= 1; index--) { const element = remarkArr[index]; ctx.fillText(element, watermarkX + 42, watermarkY - (i++) * lineHeight); } const firstRemark = remarkArr[0]; ctx.fillText('备注:' + firstRemark, watermarkX, watermarkY - (i++) * lineHeight); } //天气 if (this.data.weather && this.data.weatherValue) { ctx.fillText('天气:' + this.data.weatherValue, watermarkX, watermarkY - (i++) * lineHeight); } //海拔 if (this.data.altitude && this.data.altitudeValue) { ctx.fillText('海拔:' + this.data.altitudeValue, watermarkX, watermarkY - (i++) * lineHeight); } //时间 if (this.data.currentTime) { ctx.fillText('时间:' + this.data.currentTime, watermarkX, watermarkY - (i++) * lineHeight); } //地址 if (this.data.address && this.data.addressValue) { ctx.fillText('地址:' + this.data.addressValue, watermarkX, watermarkY - (i++) * lineHeight); } //纬度 //经度 if (this.data.lonLat && this.data.latitudeValue && this.data.longitudeValue) { ctx.fillText('纬度:' + this.data.latitudeValue, watermarkX, watermarkY - (i++) * lineHeight); ctx.fillText('经度:' + this.data.longitudeValue, watermarkX, watermarkY - (i++) * lineHeight); } this.savaToTempFile(); }, /** * canvas到临时文件 */ savaToTempFile() { let that = this wx.canvasToTempFilePath({ canvas: this.canvas, fileType: 'jpg' }).then(res => { // console.log(res); const filePath = res.tempFilePath //照片路径 this.setData({ tempImagePath: res.tempFilePath }) wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath, success: function () { }, }) wx.compressImage({ src: filePath, //图片路径 quality: 60, // 压缩质量 success: image => { this.setLastPageFlag(true); this.wmCamera.goFormPage(image.tempFilePath) }, fail: (err) => { this.setLastPageFlag(true); this.wmCamera.goFormPage(image.tempFilePath) } }) // this.saveToPhotosAlbum(res.tempFilePath); }).catch(error => { logger.error(error) // console.log(error); }) },
09-04建议引入fileType.js精准判断
wx.chooseMedia 选择Gif图片,返回的结果却是jpg?安卓 微信 8.0.50 (微信 8.0.43选择gif图返回正常) IOS 微信 8.0.50返回正常
09-04[图片]
微信小程序可以设置手机底部自带安全区的背景颜色吗?[图片] 可以设置底部红色区域手机自带安全区颜色吗,不然白色的看着太丑了
08-05下拉事件设置refresher-triggered为true
「基础库 3.4.7」 scroll-view表现异常,下拉刷新不回弹「基础库 3.4.7」 scroll-view表现异常,下拉刷新不回弹
06-11您好,看了你们的小程序,文本撤回与回退按钮显示问题有更好的解决方案么
editor组件和相关的API(EditorContext)可否安排升级一下?editor组件已经上线很久了(基础库2.7.0开始就支持),但貌似一直没见怎么更新升级过,现在的版本只能说能满足“基础”使用,但在应付一些“重度依赖”编辑器功能和性能的场景,还是有种“很吃力”的感觉。 我厂有个小程序(叫“小蜜笔记”),在开发和使用的过程中,就发现有几个功能和性能是急需升级解决的,相信它们也是大多数其他依赖编辑器的工具需要的功能: 功能方面: 1、需支持插入原生视频(现在只能插入图片模拟); 2、Mac版微信支持极差(如插入图片不能支持正常预览,只显示一个问号?的图标) 3、图片或视频(可以的话)支持位置上下移动 4、可开放更多api给开发者控制图片或视频的样式显示 性能方面: 1、iOS下性能很差,手机正常拍照的图片(4~10M大小),上传超过20张以上(指显示本地路径图片,非网络url图片;手机好点的可以更多一点,但也存在类似问题),小程序基本就会崩溃,导致一些列的操作异常,甚至内容丢失!
04-233.2.3版本已修复此问题 [图片]
touchend事件监听当两指离开后只调用一次,为啥?touchend事件监听手指离开,两指触发后,在相继离开,在版本库3.0.2触发两次,而在3.1.0只触发一次,有大佬解释下啥原因吗?最近开发好好的,莫名的不行了 [图片][图片]
2023-12-06