import React, {useEffect, useState} from "react"; import {getGrayPointList, rand} from "../../utils/util"; import {ParamTypes} from "../../constant/ParamTypes"; import {getTypeTable, QRPointType} from "../../utils/qrcodeHandler"; function listPoints(qrcode, params) { if (!qrcode) return [] const nCount = qrcode.getModuleCount(); const typeTable = getTypeTable(qrcode); const pointList = new Array(nCount); let id = 0; for (let x = 0; x < nCount; x++) { for (let y = 0; y < nCount; y++) { const posX = 3 * x, posY = 3 * y; if (typeTable[x][y] == QRPointType.ALIGN_CENTER || typeTable[x][y] == QRPointType.ALIGN_OTHER || typeTable[x][y] == QRPointType.TIMING) { if (qrcode.isDark(x, y)) { pointList.push() } else { pointList.push() } } else if (typeTable[x][y] == QRPointType.POS_CENTER) { if (qrcode.isDark(x, y)) { pointList.push() } } else if (typeTable[x][y] == QRPointType.POS_OTHER) { if (qrcode.isDark(x, y)) { pointList.push() } else { pointList.push() } } else { if (qrcode.isDark(x, y)) { pointList.push() } else { pointList.push() } } } } return pointList; } function getParamInfo() { return [ { type: ParamTypes.UPLOAD_BUTTON, key: '背景图片', default: 0, } ]; } export function getViewBox(qrcode) { if (!qrcode) return '0 0 0 0'; const nCount = qrcode.getModuleCount() * 3; return String(-nCount / 5) + ' ' + String(-nCount / 5) + ' ' + String(nCount + nCount / 5 * 2) + ' ' + String(nCount + nCount / 5 * 2); } const RendererResImage = ({qrcode, params, setParamInfo}) => { useEffect(() => { setParamInfo(getParamInfo()); }, [setParamInfo]); const [gpl, setGPL] = useState([]); useEffect(() => { getGrayPointList(params[0], qrcode.getModuleCount(), "#S-black", "#S-white").then(res => setGPL(res)); }, [params[0], qrcode]) return ( {gpl.concat(listPoints(qrcode, params))} ) } export default RendererResImage