收藏
回答

Invalid context type [webgl2] for Canvas#getContex

问题类型 插件 AppID 插件版本号 AppID 操作系统 微信版本 基础库版本
Bug wx7138a7bb793608c3 2.0.1 wx7138a7bb793608c3 iOS 8.0.43 3.2.3
<template>
  <view class="index">
    <nut-button type="primary" @click="handleClick">拍照或选择图片</nut-button>
  </view>
</template>


<script>
import { reactive, toRefs, ref, onMounted } from "vue";
import { Dongdong } from "@nutui/icons-vue-taro";
import Taro from "@tarojs/taro";
import * as paddlejs from '@paddlejs/paddlejs-core';
import '@paddlejs/paddlejs-backend-webgl';


const plugin = requirePlugin("paddlejs-plugin");
plugin.register(paddlejs, wx);
let pdjs;


export default {
  name: "Index",
  components: {
    Dongdong,
  },
  setup() {
    const state = reactive({
      tmpImage: "",
    });


    const handleClick = () => {
      wx.chooseMedia({
        count: 1,
        mediaType: ["image"],
        sourceType: ["album", "camera"],
        success: (value) => {
          let { errMsg, tempFiles } = value;
          if (errMsg != "chooseMedia:ok") {
            Taro.showToast({
              title: "选择图片失败",
              icon: "error",
              duration: 3000,
            });
            return;
          }
          let [firstImage] = tempFiles;
          state.tmpImage = firstImage.tempFilePath;


          console.log(state, `success`);
        },
        fail: (err) => {
          Taro.showToast({
            title: "操作失败",
            icon: "error",
            duration: 3000,
          });
        },
        complete: (done) => {
          console.log(done);
        },
      });
    };


    onMounted(() => {
      pdjs = new paddlejs.Runner({
        modelPath: "https://paddlejs.cdn.bcebos.com/models/mobilenetV2_nchw",
        feedShape: {
          fw: 224,
          fh: 224,
        },
        fill: "#fff",
        targetSize: {
          height: 224,
          width: 224,
        },
        mean: [0.485, 0.456, 0.406],
        std: [0.229, 0.224, 0.225],
      });
      pdjs.init().then(() => {
        // 初始化完成
        console.log("init model")
      });
    });
    return {
      ...toRefs(state),
      handleClick,
    };
  },
};
</script>


<style lang="scss">
.index {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
}
</style>


回答关注问题邀请回答
收藏

2 个回答

  • 初晨
    初晨
    04-04

    这个问题有解决方案了吗


    04-04
    有用
    回复
  • 青松
    青松
    02-08

    Invalid context type [webgl2] for Canvas#getContex


    请问你这个问题解决了没有?

    02-08
    有用
    回复
登录 后发表内容