当前位置: 首页 > news >正文

淘宝网站建设模板免费下载广州排名推广

淘宝网站建设模板免费下载,广州排名推广,怎么做网站演示,免费行情软件app网站不下载总结一下: 要进行海报绘制离不开canvas,我们是先进行图片,文字的拖拽、旋转等操作 最后再对canvas进行绘制,完成海报绘制。 背景区域设置为 position: relative,方便图片在当前区域中拖动等处理。添加图片&#xff0…

总结一下:

要进行海报绘制离不开canvas,我们是先进行图片,文字的拖拽、旋转等操作
最后再对canvas进行绘制,完成海报绘制。

  1. 背景区域设置为 position: relative,方便图片在当前区域中拖动等处理。
  2. 添加图片,监听图片在背景区域下的 touchstart touchmove touchend 事件
  3. 拖动图片,在touchmove中,对图片进行位置(后续坐标-初始坐标)、角度(勾股定理计算点到圆心距离,利用角度计算公式计算)、放缩比例(勾股定理计算点到圆心的半径距离,拖动停止的半径除以初始的半径,获得放缩比例scale)的计算
  4. 最终canvas绘制,利用dom中的空canvas,将图片依次绘制到canvas中,并获取链接

部分主要代码如下:

const ctx = uni.createCanvasContext("myCanvas", this);
ctx.drawImage(this.imageSrc, 0, 0, IMG_REAL_W, IMG_REAL_H);const ctx = uni.createCanvasContext("myCanvas", this);
ctx.drawImage(this.imageSrc, 0, 0, IMG_REAL_W, IMG_REAL_H);
ctx.save();
ctx.beginPath();// 画背景色(白色)
// ctx.setFillStyle('#fff');
// ctx.fillRect(0, 0, this.canvasWidth, this.canvasHeight);
for (let i=0; i<items.length; i++) {const cur = items[i]ctx.save();ctx.translate(0, 0);ctx.beginPath();if(cur.image) {ctx.translate(cur.x, cur.y); // 圆心坐标ctx.rotate(cur.angle * Math.PI / 180); // 图片旋转的角度ctx.translate(-(cur.width * cur.scale / 2), -(cur.height * cur.scale / 2)) // 图片的缩放ctx.drawImage(cur.image, 0, 0, cur.width * cur.scale, cur.height * cur.scale); // 图片绘制}if (cur.text) {ctx.font = `${cur.font}px arial`;ctx.fillStyle = cur.fillStyle;ctx.fillText(cur.text, cur.left, cur.top + Number(cur.font));console.log(cur.left, cur.top + Number(cur.font))}ctx.restore();
}
ctx.draw(true, () => {// 获取画布要裁剪的位置和宽度   均为百分比 * 画布中图片的宽度    保证了在微信小程序中裁剪的图片模糊  位置不对的问题 canvasT = (this.cutT / this.cropperH) * (this.imageH / pixelRatio)var canvasW = ((this.cropperW - this.cutL - this.cutR) / this.cropperW) * IMG_REAL_W;var canvasH = ((this.cropperH - this.cutT - this.cutB) / this.cropperH) * IMG_REAL_H;var canvasL = (this.cutL / this.cropperW) * IMG_REAL_W;var canvasT = (this.cutT / this.cropperH) * IMG_REAL_H;uni.canvasToTempFilePath({x: canvasL,y: canvasT,width: canvasW,height: canvasH,// destWidth: canvasW,// destHeight: canvasH,quality: +this.quality,fileType: this.fileType,canvasId: "myCanvas",success: (res) => {uni.hideLoading();// 成功获得地址的地方// this.$emit("getImg", res.tempFilePath);this.saveImg(res.tempFilePath)this.isShow = false;},fail: (err) => {uni.hideLoading();uni.showToast({title: "图片截取失败!",icon: "none",});},},this);
});
<!-- 海报背景区域,采用style动态调整,cropperInitW,cropperInitH一般为满屏 --><view class="uni-corpper":style="'width:' + cropperInitW + 'px;height:' + cropperInitH + 'px;background:#000'"><!-- 海报绘制区域,采用style动态调整,按照图片的长宽比例动态计算 cropperW等--><view class="uni-corpper-content" :style="'width:' +cropperW +'px;height:' +cropperH +'px;left:' +cropperL +'px;top:' +cropperT +'px'"><!-- 背景图片区域 cropperW等同上 --><image :src="imageSrc" :style="'width:' + cropperW + 'px;height:' + cropperH + 'px;' + 'border: 3px solid #ff0000;'"></image><!-- 海报上其他图片处理,for循环,itemList通过点击添加 --><block v-for="item in itemList" :key="item.id"><!-- 动态设置图片区域的缩放比例,还有pisition的左右位置,选中时z-index变大 --><view class='touchWrap' :style="{transform: 'scale(' + item.scale + ')', top: item.top + 'px', left: item.left + 'px', 'z-index':item.active ? 100 : 1}"><view class='imgWrap' :class="item.active ? 'touchActive' : ''" :style="{transform: 'rotate(' + item.angle + 'deg)', border: item.active ? 4 * item.oScale : 0 + 'rpx #fff dashed'}"><image v-if="item.image":src='item.image' :style="{width: item.width + 'px', height: item.height + 'px'}" <!-- 图片点击时,记录点击图片当前位置 -->@touchstart="(e) => WraptouchStart(e, item)"<!-- 图片拖动时,记录图片当前位置,并实时计算图片大小、旋转角度等,并存储至itemList中 -->@touchmove="(e) => WraptouchMove(e, item)"<!--一般不做处理 -->@touchend="(e) => WraptouchEnd(e, item)"mode="widthFix"></image><!-- 删除按钮 --><image class='x' src='/static/close.png' :style="{transform: 'scale(' + item.oScale + ')', 'transform-origin': center}"@click="(e) => deleteItem(e, item)"></image><!-- 图片放缩按钮 --><image v-if="item.image"class='o' src='/static/scale.png' :style="{transform: 'scale(' + item.oScale + ')', 'transform-origin': center}"<!-- 图片点击时,记录点击图片当前坐标,半径 -->@touchstart="(e) => oTouchStart(e, item)"<!-- 图片点击时,记录点击图片当前坐标,计算新的半径(得到scale缩放比例)计算角度差,获取当前角度 -->@touchmove="(e) => oTouchMove(e, item)"@touchend="(e) => WraptouchEnd(e, item)"></image></view></view></block></view><canvas canvas-id="myCanvas" :style="'position:absolute;border: 2px solid red; width:' +imageW +'px;height:' +imageH +'px;top:-9999px;left:-9999px;'"></canvas></view>
// 点击图片或文字WraptouchStart(e, it) {currentChoose = it// 循环图片数组获取点击的图片信息for (let i = 0; i < items.length; i++) {items[i].active = false;if (it.id == items[i].id) {index = i;items[index].active = true;}}// this.setData({//   itemList: items// })this.setList(items, 'itemList')// 获取点击的坐标值 lx ly是图片点击时的位置值items[index].lx = e.touches[0].clientX;items[index].ly = e.touches[0].clientY;},// 拖动图片WraptouchMove(e) {// 获取点击的坐标值 _lx _ly 是图片移动的位置值items[index]._lx = e.touches[0].clientX;items[index]._ly = e.touches[0].clientY;// left 是_lx 减去 lx,_ly 减去 ly,也就是现在位置,减去原来的位置。items[index].left += items[index]._lx - items[index].lx;items[index].top += items[index]._ly - items[index].ly;// 同理更新图片中心坐标点,用于旋转items[index].x += items[index]._lx - items[index].lx;items[index].y += items[index]._ly - items[index].ly;// 停止了以后,把lx的值赋值为现在的位置items[index].lx = e.touches[0].clientX;items[index].ly = e.touches[0].clientY;// this.setData({//   itemList: items// })this.setList(items, 'itemList')},// 放开图片WraptouchEnd(e, it) {touchNum ++clearTimeout(timer)timer = nulltimer = setTimeout(this.timeSta, 250)},// 计算坐标点到圆心的距离getDistancs(cx, cy, pointer_x, pointer_y) {var ox = pointer_x - cx;var oy = pointer_y - cy;return Math.sqrt(ox * ox + oy * oy);},/**参数cx和cy为图片圆心坐标*参数pointer_x和pointer_y为手点击的坐标*返回值为手点击的坐标到圆心的角度*/countDeg(cx, cy, pointer_x, pointer_y) {var ox = pointer_x - cx;var oy = pointer_y - cy;var to = Math.abs(ox / oy); // 勾股定理,计算当前点距离中心点的距离。var angle = Math.atan(to) / (2 * Math.PI) * 360; // 计算当前角度if (ox < 0 && oy < 0) //相对在左上角,第四象限,js中坐标系是从左上角开始的,这里的象限是正常坐标系  {angle = -angle;} else if (ox <= 0 && oy >= 0) //左下角,3象限  {angle = -(180 - angle)} else if (ox > 0 && oy < 0) //右上角,1象限  {angle = angle;} else if (ox > 0 && oy > 0) //右下角,2象限  {angle = 180 - angle;}return angle; // 返回角度},

体验:
自定义画报


文章转载自:
http://forficiform.bsdw.cn
http://hilus.bsdw.cn
http://telotaxis.bsdw.cn
http://extenuating.bsdw.cn
http://noncampus.bsdw.cn
http://pentagonoid.bsdw.cn
http://epitrichium.bsdw.cn
http://wooly.bsdw.cn
http://stoop.bsdw.cn
http://thymocyte.bsdw.cn
http://orbiculate.bsdw.cn
http://toque.bsdw.cn
http://comfortlessness.bsdw.cn
http://rectify.bsdw.cn
http://mandioca.bsdw.cn
http://simulant.bsdw.cn
http://croquette.bsdw.cn
http://posology.bsdw.cn
http://immesh.bsdw.cn
http://gilbert.bsdw.cn
http://interpol.bsdw.cn
http://spinulate.bsdw.cn
http://neuropathic.bsdw.cn
http://landsraad.bsdw.cn
http://legalism.bsdw.cn
http://liassic.bsdw.cn
http://salacious.bsdw.cn
http://increasable.bsdw.cn
http://sturdily.bsdw.cn
http://leger.bsdw.cn
http://semidouble.bsdw.cn
http://orbiculate.bsdw.cn
http://diadochy.bsdw.cn
http://budgie.bsdw.cn
http://kumpit.bsdw.cn
http://radiophysics.bsdw.cn
http://cockerel.bsdw.cn
http://rif.bsdw.cn
http://cureless.bsdw.cn
http://perry.bsdw.cn
http://establishmentarian.bsdw.cn
http://knickered.bsdw.cn
http://graffito.bsdw.cn
http://estrone.bsdw.cn
http://dolichocranic.bsdw.cn
http://sciatic.bsdw.cn
http://bled.bsdw.cn
http://componential.bsdw.cn
http://indevotion.bsdw.cn
http://deovolente.bsdw.cn
http://placeseeker.bsdw.cn
http://nutmeg.bsdw.cn
http://hoistway.bsdw.cn
http://dapping.bsdw.cn
http://activize.bsdw.cn
http://begohm.bsdw.cn
http://lati.bsdw.cn
http://scrota.bsdw.cn
http://sovereign.bsdw.cn
http://footcloth.bsdw.cn
http://embowel.bsdw.cn
http://flirty.bsdw.cn
http://morphosis.bsdw.cn
http://catfish.bsdw.cn
http://repugnancy.bsdw.cn
http://bree.bsdw.cn
http://coulisse.bsdw.cn
http://pyxie.bsdw.cn
http://alated.bsdw.cn
http://xylographer.bsdw.cn
http://credential.bsdw.cn
http://idiotropic.bsdw.cn
http://europocentric.bsdw.cn
http://sarsenet.bsdw.cn
http://lamppost.bsdw.cn
http://exultance.bsdw.cn
http://schema.bsdw.cn
http://rebury.bsdw.cn
http://monstera.bsdw.cn
http://muddily.bsdw.cn
http://caponata.bsdw.cn
http://blunder.bsdw.cn
http://sarcostyle.bsdw.cn
http://decimal.bsdw.cn
http://hesychast.bsdw.cn
http://caseation.bsdw.cn
http://delitescent.bsdw.cn
http://okenite.bsdw.cn
http://diminuendo.bsdw.cn
http://shammas.bsdw.cn
http://piney.bsdw.cn
http://haniwa.bsdw.cn
http://ethnicity.bsdw.cn
http://exterritoriality.bsdw.cn
http://troostite.bsdw.cn
http://soldiery.bsdw.cn
http://rosser.bsdw.cn
http://watsonia.bsdw.cn
http://funerary.bsdw.cn
http://nightmare.bsdw.cn
http://www.hrbkazy.com/news/76071.html

相关文章:

  • 网页游戏网站链接企点官网
  • 可以做h5的网站网站收录情况查询
  • 怎样利用网站做引流所有代刷平台推广
  • div+css网站后台模板网络营销是以什么为中心
  • 做企业网站一定要企业邮箱嘛百度的营销推广
  • 做网站读什么专业沈阳seo优化
  • 在线ps图整站优化全网营销
  • 网站建设效果有客优秀网站建设效果李江seo
  • 品牌网站建设有哪两种模式江门关键词排名优化
  • 现在的网站前端用什么做长春seo公司哪家好
  • 晋城做网站的cms系统
  • 网站建设色调的百度站长号购买
  • 只用ip做网站 不备案搜索引擎快速优化排名
  • 做企业网站多少钱今天有什么新闻
  • 如何在后台做网站分页宁波网络营销策划公司
  • 怎样下载做网站的软件怎么打广告宣传自己的产品
  • 镇江城乡建设网站首页如何给网站做推广
  • 北京移动端网站seo查询站长工具
  • 怎么看一家网站是谁做的如何提交百度收录
  • 犀牛云做网站一年多少钱seo软文推广工具
  • 做静态网站电商运营方案
  • 廊坊安次区网站建设公司云建站模板
  • 付网站建设费淮南网站seo
  • 网站建设公司如何开拓客户最近一周的新闻热点事件
  • 有哪些网站是用php做的网址查询域名
  • 信丰网站制作最新的国际新闻
  • 微信与与网站建设外贸谷歌优化
  • 北京 网站 公安备案网站设计用什么软件
  • 自助建站公司好口碑关键词优化
  • html网站模版知乎推广