mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2025-04-30 14:24:27 +02:00
working
This commit is contained in:
parent
346d1dddba
commit
5abbec94c4
@ -8,7 +8,12 @@ globalStyle(`${DrawImageMain} > canvas`, {
|
|||||||
position: "absolute",
|
position: "absolute",
|
||||||
top: "0",
|
top: "0",
|
||||||
left: "0",
|
left: "0",
|
||||||
opacity: ".5",
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
});
|
||||||
|
|
||||||
|
globalStyle(`${DrawImageMain} > canvas:first-of-type`, {
|
||||||
|
opacity: ".7",
|
||||||
});
|
});
|
||||||
|
|
||||||
globalStyle(`${DrawImageMain} > img`, {
|
globalStyle(`${DrawImageMain} > img`, {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React, { useRef, useState, useCallback, useEffect } from "react";
|
import React, { useRef, useState, useEffect } from "react";
|
||||||
|
|
||||||
// https://github.com/embiem/react-canvas-draw
|
// https://github.com/embiem/react-canvas-draw
|
||||||
|
|
||||||
@ -23,6 +23,42 @@ export default function DrawImage({ imageData, brushSize, brushShape, brushColor
|
|||||||
const cursorRef = useRef<HTMLCanvasElement>(null);
|
const cursorRef = useRef<HTMLCanvasElement>(null);
|
||||||
const [isUpdating, setIsUpdating] = useState(false);
|
const [isUpdating, setIsUpdating] = useState(false);
|
||||||
|
|
||||||
|
const [canvasWidth, setCanvasWidth] = useState(512);
|
||||||
|
const [canvasHeight, setCanvasHeight] = useState(512);
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log(imageData);
|
||||||
|
const img = new Image();
|
||||||
|
img.onload = () => {
|
||||||
|
setCanvasWidth(img.width);
|
||||||
|
setCanvasHeight(img.height);
|
||||||
|
|
||||||
|
}
|
||||||
|
img.src = imageData;
|
||||||
|
|
||||||
|
}, [imageData]);
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// when the brush color changes, change the color of all the
|
||||||
|
// drawn pixels to the new color
|
||||||
|
if (drawingRef.current) {
|
||||||
|
const ctx = drawingRef.current.getContext("2d");
|
||||||
|
const imageData = ctx.getImageData(0, 0, canvasWidth, canvasHeight);
|
||||||
|
const data = imageData.data;
|
||||||
|
for (let i = 0; i < data.length; i += 4) {
|
||||||
|
if (data[i + 3] > 0) {
|
||||||
|
data[i] = parseInt(brushColor, 16);
|
||||||
|
data[i + 1] = parseInt(brushColor, 16);
|
||||||
|
data[i + 2] = parseInt(brushColor, 16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx.putImageData(imageData, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, [brushColor]);
|
||||||
|
|
||||||
const _handleMouseDown = (
|
const _handleMouseDown = (
|
||||||
e: React.MouseEvent<HTMLCanvasElement, MouseEvent>
|
e: React.MouseEvent<HTMLCanvasElement, MouseEvent>
|
||||||
) => {
|
) => {
|
||||||
@ -78,7 +114,7 @@ export default function DrawImage({ imageData, brushSize, brushShape, brushColor
|
|||||||
|
|
||||||
if (isErasing) {
|
if (isErasing) {
|
||||||
const offset = brushSize / 2;
|
const offset = brushSize / 2;
|
||||||
// draw a quare outline
|
// draw a quare
|
||||||
ctx.lineWidth = 2;
|
ctx.lineWidth = 2;
|
||||||
ctx.lineCap = 'butt';
|
ctx.lineCap = 'butt';
|
||||||
ctx.strokeStyle = brushColor;
|
ctx.strokeStyle = brushColor;
|
||||||
@ -132,13 +168,13 @@ export default function DrawImage({ imageData, brushSize, brushShape, brushColor
|
|||||||
<img src={imageData} />
|
<img src={imageData} />
|
||||||
<canvas
|
<canvas
|
||||||
ref={drawingRef}
|
ref={drawingRef}
|
||||||
width={512}
|
width={canvasWidth}
|
||||||
height={512}
|
height={canvasHeight}
|
||||||
></canvas>
|
></canvas>
|
||||||
<canvas
|
<canvas
|
||||||
ref={cursorRef}
|
ref={cursorRef}
|
||||||
width={512}
|
width={canvasWidth}
|
||||||
height={512}
|
height={canvasHeight}
|
||||||
onMouseDown={_handleMouseDown}
|
onMouseDown={_handleMouseDown}
|
||||||
onMouseUp={_handleMouseUp}
|
onMouseUp={_handleMouseUp}
|
||||||
onMouseMove={_handleMouseMove}
|
onMouseMove={_handleMouseMove}
|
||||||
|
@ -53,7 +53,6 @@ export default function InpaintingPanel() {
|
|||||||
// };
|
// };
|
||||||
|
|
||||||
const _handleBrushShape = (e: ChangeEvent<HTMLInputElement>) => {
|
const _handleBrushShape = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
console.log("brush shape", e.target.value);
|
|
||||||
setBrushShape(e.target.value);
|
setBrushShape(e.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user