re:03 2022-06-01 18:06 采纳率: 73.3%
浏览 741
已结题

js-web-screen-shot截图空白

js-web-screen-shot截图空白

就正常使用组件,在别的地方都可以但是,换过去以后就直接空白具体过程是

img

img

这2个图片分别是启动截图功能能未选择区域,和选中区域后空白的情况,有没有人知道是怎么回事

  • 写回答

2条回答 默认 最新

  • re:03 2022-06-02 10:16
    关注
    
    <template>
      <div class="toolbarOutline">
        名称<el-input
          v-model="name"
          class="inputGeneral"
          placeholder="请选择"
        ></el-input>
        <div style="margin-left: 1%">
          <el-color-picker
            v-model="wireColor"
            size="mini"
            :show-alpha="true"
            @change="colorVariation('wireColor')"
          ></el-color-picker>
        </div>
        <div class="General">线形</div>
        <el-select
          v-model="SelectValue"
          clearable
          class="inputGeneral"
          placeholder="请选择"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <div class="General">颜色</div>
        <el-select
          v-model="colorValue"
          clearable
          class="inputGeneral"
          placeholder="请选择"
        >
          <el-option
            v-for="item in transparence"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <div style="margin-left: 1%">
          <el-color-picker
            v-model="SubstanceColor"
            size="mini"
            :show-alpha="true"
            @change="colorVariation('SubstanceColor')"
          ></el-color-picker>
        </div>
    
        <!-- 截图按钮 -->
        <button class="Cut" @click="printscreen"></button>
      </div>
    </template>
    
    <script>
    import ScreenShort from 'js-web-screen-shot'
    export default {
      data() {
        return {
          name: null,
          wireColor: '#fff',
          SubstanceColor: '#FF0000',
          SelectValue: 'solid',
          colorValue: '100',
          options: [
            {
              label: '实线',
              value: 'solid',
            },
            {
              label: '虚线',
              value: 'dashed',
            },
          ],
          transparence: [
            {
              label: '10%',
              value: '10',
            },
            {
              label: '20%',
              value: '20',
            },
            {
              label: '30%',
              value: '30%',
            },
            {
              label: '40%',
              value: '40%',
            },
            {
              label: '50%',
              value: '50',
            },
            {
              label: '60%',
              value: '60',
            },
            {
              label: '70%',
              value: '70',
            },
            {
              label: '80%',
              value: '80',
            },
            {
              label: '90%',
              value: '90',
            },
            {
              label: '100%',
              value: '100',
            },
          ],
          uploadlist: [],
        }
      },
      methods: {
        //截图
        //开始截图
        printscreen() {
          // eslint-disable-next-line no-unused-vars
          var timer = setTimeout(() => {
            // eslint-disable-next-line no-unused-vars
            const screenShotHandler = new ScreenShort(
              {
                enableWebRtc: false, //是否显示选项框
                level: 99, //层级级别
                completeCallback: this.callback,
                closeCallback: this.closeFn,
              },
              0
            )
          })
        },
        /**
         * 根据图片生成画布
         */
        convertImageToCanvas(image) {
          var canvas = document.createElement('canvas')
          canvas.width = image.width
          canvas.height = image.height
          canvas.getContext('2d').drawImage(image, 0, 0)
          return canvas
        },
        /**
         * 生成图片
         * 截图确认按钮回调函数
         */
        callback(base64data) {
          let _this = this
          var image = new Image()
          image.src = base64data
          image.onload = () => {
            var canvas = _this.convertImageToCanvas(image)
            var url = canvas.toDataURL('image/jpeg')
            // 在页面展示的数组,次数组是要把截图成功后的图片在页面上展示出来的数组,可以根据自己项目的需求进行添加
            _this.downloadFile(url)
            _this.uploadlist.push({ image: url })
            for (var i = 0; i < _this.uploadlist.length; i++) {
              if (_this.uploadlist.length >= 6) {
                _this.uploadhide = false
              }
            }
            console.log(_this.uploadlist, 'push')
    
            this.$message({
              type: 'success',
              message: '截图成功',
            })
          }
        },
        //下载截图
        downloadFile(capture) {
          const saveInfo = {
            //导出文件格式自己定义,我这里用的是时间作为文件名
            download: '截图' + new Date() + `.png`,
            href: capture,
          }
          const element = document.createElement('a')
          element.style.display = 'none'
          for (const key in saveInfo) {
            element.setAttribute(key, saveInfo[key])
          }
          document.body.appendChild(element)
          element.click()
          setTimeout(() => {
            document.body.removeChild(element)
          }, 300)
        },
        ///调色器
        colorVariation(obj) {
          console.log(obj)
          // eslint-disable-next-line no-unused-vars
          let _this = this
          if (obj == 'wireColor') {
            if (this.wireColor.search('rgba') != -1) {
              _this.wireColor = _this.hexify(_this.wireColor)
            }
          } else {
            if (this.SubstanceColor.search('rgba') != -1) {
              _this.SubstanceColor = _this.hexify(_this.SubstanceColor)
            }
          }
        },
        //rgb格式转16进制
        hexify(color) {
          var values = color
            .replace(/rgba?\(/, '')
            .replace(/\)/, '')
            .replace(/[\s+]/g, '')
            .split(',')
          var a = parseFloat(values[3] || 1),
            r = Math.floor(a * parseInt(values[0]) + (1 - a) * 255),
            g = Math.floor(a * parseInt(values[1]) + (1 - a) * 255),
            b = Math.floor(a * parseInt(values[2]) + (1 - a) * 255)
          return (
            '#' +
            ('0' + r.toString(16)).slice(-2) +
            ('0' + g.toString(16)).slice(-2) +
            ('0' + b.toString(16)).slice(-2)
          )
        },
      },
    }
    </script>
    
    <style scoped>
    .toolbarOutline {
      display: flex;
      white-space: nowrap;
      justify-content: space-around;
      line-height: 32px;
      width: 45%;
      /* height: 4%; */
      /* font-size: 0.9rem; */
      border-radius: 8px;
      background: aliceblue;
      position: absolute;
      bottom: 20px;
      left: 30%;
      z-index: 999;
      padding: 1%;
    }
    .Cut {
      width: 30px;
      border: 0.5px solid #939191;
      border-radius: 5px;
      height: 30px;
      /* 按钮底图 */
      background: rgb(255, 255, 255) url('../assets/img/CutTheScreenshot.png') round;
      cursor: pointer;
      margin-left: 1%;
    }
    .inputGeneral {
      width: 26%;
      margin-left: 1%;
    }
    .colorPicker {
      margin-left: 1%;
      width: 20%;
      display: flex;
    }
    .General {
      margin-left: 1%;
    }
    /deep/
      .el-color-picker
      .el-color-picker__trigger
      .el-color-picker__color
      .el-color-picker__color-inner
      .el-color-picker__icon {
      display: none;
    }
    </style>
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 8月30日
  • 已采纳回答 8月22日
  • 修改了问题 6月2日
  • 创建了问题 6月1日

悬赏问题

  • ¥15 nopCommerce开发问题
  • ¥15 torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with signal SIGKILL
  • ¥15 QuartusⅡ15.0编译项目后,output_files中的.jdi、.sld、.sof不更新怎么解决
  • ¥15 pycharm输出和导师的一样,但是标红
  • ¥15 想问问富文本拿到的html怎么转成docx的
  • ¥15 我看了您的文章,遇到了个问题。
  • ¥15 GitHubssh虚拟机连接不上
  • ¥15 装完kali之后下载Google输入法 重启电脑后出现以下状况 且退不出去 桌面消失 反复重启没用
  • ¥15 ESP-IDP-BLE配网连接wifi
  • ¥15 ue2.6.12版本用的若以,安装gojs,引入import * as go from 'gojs';报错