이정민

canvas 가져오기

1 /// <reference path="react-image-editor.d.ts" /> 1 /// <reference path="react-image-editor.d.ts" />
2 import ImageEditor from "@toast-ui/react-image-editor"; 2 import ImageEditor from "@toast-ui/react-image-editor";
3 +import { useEffect, useState } from "react";
3 import "tui-image-editor/dist/tui-image-editor.css"; 4 import "tui-image-editor/dist/tui-image-editor.css";
4 5
5 const ToastEditor = () => { 6 const ToastEditor = () => {
7 + const [lowerCanvas, setLowerCanvas] = useState<HTMLCanvasElement>();
8 + // console.log(
9 + // document.getElementsByClassName("lower-canvas")[0]?.toDataURL("image/png")
10 + // );
11 + console.log("c");
12 +
13 + // const [upperCanvas, setUpperCanvas] = useState(
14 + // document.getElementsByClassName("upper-canvas ")[0]
15 + // );
16 +
17 + useEffect(() => {
18 + window?.addEventListener("click", () => {
19 + setLowerCanvas(
20 + document.getElementsByClassName("lower-canvas")[0] as HTMLCanvasElement
21 + );
22 + });
23 + }, []);
24 +
25 + useEffect(() => {
26 + const img = lowerCanvas?.toDataURL("image/png");
27 + let w = window.open();
28 + if (w?.window) w.document.body.innerHTML = "<img src='" + img + "'>";
29 +
30 + console.log("b");
31 + if (lowerCanvas?.getContext) {
32 + console.log(lowerCanvas.getContext("2d"));
33 + }
34 + }, [lowerCanvas?.toDataURL("image/png")]);
35 +
6 return ( 36 return (
7 <ImageEditor 37 <ImageEditor
8 includeUI={{ 38 includeUI={{
......