feat: 🎸 图片初步生成
parent
2a98d30935
commit
d1025c2591
@ -1,11 +1,37 @@
|
||||
import React, { useEffect } from "react";
|
||||
import { getHelloWorld } from "../service";
|
||||
import React, { useState } from "react";
|
||||
import { generatePicture, getHelloWorld } from "../service";
|
||||
import { Button } from "@mui/material";
|
||||
|
||||
export const GameUI = () => {
|
||||
useEffect(() => {
|
||||
getHelloWorld().then((result) => {
|
||||
console.log(result);
|
||||
});
|
||||
}, []);
|
||||
return <div></div>;
|
||||
const [code, setCode] = useState("");
|
||||
return (
|
||||
<div>
|
||||
<Button
|
||||
onClick={() => {
|
||||
console.time();
|
||||
generatePicture().then((result) => {
|
||||
console.log(result);
|
||||
const source = result.data.split("\n");
|
||||
const fields = {};
|
||||
source?.forEach((d) => {
|
||||
const [name, s] = d.split(":");
|
||||
fields[name] = s;
|
||||
});
|
||||
console.timeEnd();
|
||||
setCode(fields.data);
|
||||
// const data = new Uint8ClampedArray(buffer);
|
||||
// console.log(data);
|
||||
// const imageData = new ImageData(data, 256, 384);
|
||||
// const canvas = document.getElementById("picture");
|
||||
// const context = canvas.getContext("2d");
|
||||
// context.putImageData(imageData);
|
||||
});
|
||||
}}
|
||||
>
|
||||
召唤
|
||||
</Button>
|
||||
<canvas id="picture" width={256} height={384}></canvas>
|
||||
<img src={`data:image/jpeg;base64,${code}`}></img>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue