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

有了域名搭建网站详细步骤手机如何制作网页链接

有了域名搭建网站详细步骤,手机如何制作网页链接,网站建设工作室创业计划书,站长工具alexa排名文章标题 01 功能说明02 使用方式 & 效果图2.1 基础用法2.2 拍照 底部定点水印 预览2.3 拍照 整体背景水印 预览 03 全部代码3.1 页面布局 html3.2 业务核心 js3.3 基础样式 css 01 功能说明 需求:小程序端需要调用前置摄像头进行拍照,并且将拍…

文章标题

  • 01 功能说明
  • 02 使用方式 & 效果图
    • 2.1 基础用法
    • 2.2 拍照 + 底部定点水印 + 预览
    • 2.3 拍照 + 整体背景水印 + 预览
  • 03 全部代码
    • 3.1 页面布局 html
    • 3.2 业务核心 js
    • 3.3 基础样式 css

01 功能说明

需求:小程序端需要调用前置摄像头进行拍照,并且将拍好的照片添加水印后返回。下面的代码支持 底部定点水印整体背景水印

技术栈uniappvue

迭代:后期还可以继续 扩展多方位的定点水印 和 支持绘制多句话的背景水印。

02 使用方式 & 效果图

文件路径:"@/components/CameraSnap.vue"

2.1 基础用法

// (1)仅拍照 + 预览
<CameraSnap />// (4)仅给图片添加水印 + 预览
<CameraSnap photoSrc="xxx" :mark-list="['今天天气很好','2023-01-01 00:00:00']" 
/>

2.2 拍照 + 底部定点水印 + 预览

使用方式:

<CameraSnap :mark-list="['今天天气很好','2023-01-01 00:00:00']" textSize="24" useTextMask 
/>

效果如下:
拍照_底部定点水印_预览

2.3 拍照 + 整体背景水印 + 预览

使用方式:

// 若不设置 markType,则默认为 底部定点水印
// 目前背景水印只会取 markList 的第一项来绘制背景水印
<CameraSnap markType="background" :mark-list="['今天天气很好']" textColor="rgba(255,255,255,0.5)"  
/>

效果如下:
拍照_整体背景水印_预览

03 全部代码

uni-app camera 的官方文档:https://uniapp.dcloud.net.cn/component/camera.html#camera

3.1 页面布局 html

<template><view class="camera-wrapper"><!-- 拍照 --><template v-if="!snapSrc"><!-- 相机 --><camera device-position="front" flash="off" @error="handleError" class="image-size"><view class="photo-btn" @click="handleTakePhoto">拍照</view></camera><!-- 水印 --><canvas canvas-id="photoMarkCanvas" id="photoMarkCanvas" class="mark-canvas":style="{width: canvasWidth+'px',height: canvasHeight+'px'}" /></template><!-- 预览 --><template v-else><view class="re-photo-btn" @click="handleRephotograph">重拍</view><image class="image-size" :src="snapSrc"></image></template></view>
</template>

3.2 业务核心 js

<script>export default {name: 'CameraSnap',props: {// 照片地址(若传递了照片地址,则默认为预览该照片或添加水印后预览)photoSrc: {type: String,default: ""},// 水印类型markType: {type: String,default: "fixed", // 定点水印 fixed,背景水印 background},// 水印文本列表(支持多行)markList: {type: Array,default: () => []},textColor: {type: String,default: "#FFFFFF"},textSize: {type: Number,default: 32},// 定点水印的遮罩(为了让水印更清楚)useTextMask: {type: Boolean,default: true}},data() {return {snapSrc: "",canvasWidth: "",canvasHeight: "",}},watch: {photoSrc: {handler: function(newValue, oldValue) {if (newValue) {this.getWaterMarkImgPath(newValue)}},immediate: true}},methods: {handleTakePhoto() {const ctx = uni.createCameraContext();ctx.takePhoto({quality: 'high',success: (res) => {const imgPath = res.tempImagePathif (this.markList.length) {this.getWaterMarkImgPath(imgPath)} else {this.snapSrc = imgPath;console.log("default", this.snapSrc)this.$emit('complete', imgPath)}}});},handleRephotograph() {this.snapSrc = ""},handleError(err) {uni.showModal({title: '警告',content: '若不授权使用摄像头,将无法使用拍照功能!',cancelText: '不授权',confirmText: '授权',success: (res) => {if (res.confirm) {// 允许打开授权页面,调起客户端小程序设置界面,返回用户设置的操作结果uni.openSetting({success: (res) => {res.authSetting = { "scope.camera": true }},})} else if (res.cancel) {// 拒绝打开授权页面uni.showToast({ title: '您已拒绝授权,无法进行拍照', icon: 'error', duration: 2500 });}}})},setWaterMark(context, image) {const listLength = this.markList?.lengthswitch (this.markType) {case 'fixed':const spacing = 4 // 行间距const paddingTopBottom = 20 // 整体上下间距// 默认每行的高度 = 字体高度 + 向下间隔const lineHeight = this.textSize + spacingconst allLineHeight = lineHeight * listLength// 矩形遮罩的 Y 坐标const maskRectY = image.height - allLineHeight// 绘制遮罩层if (this.useTextMask) {context.setFillStyle('rgba(0,0,0,0.4)');context.fillRect(0, maskRectY - paddingTopBottom, image.width, allLineHeight + paddingTopBottom)}// 文本与 x 轴之间的间隔const textX = 10// 文本一行的最大宽度(减去 20 是为了一行的左右留间隙)const maxWidth = image.width - 20context.setFillStyle(this.textColor)context.setFontSize(this.textSize)this.markList.forEach((item, index) => {// 因为文本的 Y 坐标是指文本基线的 Y 轴坐标,所以要获取文本顶部的 Y 坐标const textY = maskRectY - paddingTopBottom / 2 + this.textSize + lineHeight * indexcontext.fillText(item, textX, textY, maxWidth);})break;case 'background':context.translate(0, 0);context.rotate(30 * Math.PI / 180);context.setFillStyle(this.textColor)context.setFontSize(this.textSize)const colSize = parseInt(image.height / 6)const rowSize = parseInt(image.width / 2)let x = -rowSizelet y = -colSize// 循环绘制 5 行 6 列 的文字for (let i = 1; i <= 6; i++) {for (let j = 1; j <= 5; j++) {context.fillText(this.markList[0], x, y, rowSize)// 每个水印间隔 20x += rowSize + 20}y += colSizex = -rowSize}break;}context.save();},getWaterMarkImgPath(src) {const _this = thisuni.getImageInfo({src,success: (image) => {this.canvasWidth = image.widththis.canvasHeight = image.heightconst context = uni.createCanvasContext("photoMarkCanvas", this)context.drawImage(src, 0, 0, image.width, image.height)// 设置水印this.setWaterMark(context, image)// 若还需其他操作,可在操作之后叠加保存:context.restore()// 将画布上的图保存为图片context.draw(false, () => {setTimeout(() => {uni.canvasToTempFilePath({destWidth: image.width,destHeight: image.height,canvasId: 'photoMarkCanvas',fileType: 'jpg',success: function(res) {_this.snapSrc = res.tempFilePathconsole.log("water", _this.snapSrc)_this.$emit('complete', _this.snapSrc)}},_this);}, 200)});}})},}}
</script>

3.3 基础样式 css

<style lang="scss" scoped>.camera-wrapper {position: relative;}.mark-canvas {position: absolute;/* 将画布移出展示区域 */top: -200vh;left: -200vw;}.image-size {width: 100%;height: 100vh;}.photo-btn {position: absolute;bottom: 100rpx;left: 50%;transform: translateX(-50%);width: 140rpx;height: 140rpx;line-height: 140rpx;text-align: center;background-color: #000000;border-radius: 50%;border: 10rpx solid #ffffff;color: #fff;}.re-photo-btn {position: absolute;bottom: 80rpx;right: 40rpx;padding: 10rpx 20rpx;background-color: #000000;border-radius: 10%;border: 6rpx solid #ffffff;color: #fff}
</style>
http://www.dt0577.cn/news/22684.html

相关文章:

  • 白云商城型网站建设网络公关公司收费
  • 自动化东莞网站建设免费com网站域名注册
  • 做网站一般费用多少百度网站下载安装
  • 用台电脑做网站seo小白入门
  • 义乌开锁做网站哪个好关键词在线下载
  • 如何做百度推广的网站seo 优化技术难度大吗
  • 网站 设计 案例 简单广告开户
  • 找人代做网站费用珠海百度搜索排名优化
  • 网站首页图片代码网站数据
  • 广西汽车网网站建设seo 排名 优化
  • 怎么做集合网站seo入门教程
  • 商丘市做网站的公司百度导航怎么下载
  • 个人备案的网站可以做商城厦门网站到首页排名
  • 哪个网站做图书广告好购买模板建站
  • 推广公司组织架构宁波优化网站厂家
  • 运动鞋子网站建设规划书上海网站设计公司
  • 郑州做企业网站哪家好百度搜索app下载
  • 做网站侵权吗优化网站seo
  • 华泰保险公司官方网站吉林seo网络推广
  • 什么网站上做推广效果比较好河源网站seo
  • 顺德大良网站建设游戏推广怎么做挣钱
  • wordpress flat 下载自媒体seo优化
  • 网页设计与网站建设教材专业做网站的公司
  • 网站如何验收公司全网推广
  • 网站名称与主体性质不符苏州推广排名
  • 网站怎么做跳转安全百度网址怎么输入?
  • 高端网站免费引流人脉推广软件
  • 做电商网站公司建网站怎么建
  • 微信开发者平台在哪里找seo在线诊断工具
  • 网站做分布式部署优化大师win7官方免费下载