Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
DrawImg function put the previous img on canvas

hi I build a Drawing App that when you draw something on it you can choose suggestion picture to add it in canvas . But there is a problem , for example I have three suggested Image ,when user click on #img1 nothing happen , if continue to drawing and for second time click on #img2 ,#img1 is place on the canvas .Since I am sure that the problem is with the DrawPicture function(the function that contains drawimg), I will put the related codes here so that you can debug it more easily.

my Three img and canvas Code :

<div>
          <img
            id={"img1"}
            src={Butterfly}
            onClick={
              (event) => {
                takePicture(event);
                DrawPicture();
                setPointsId(elements.length)
              }
            }
            style={{ cursor: "pointer" }}
            alt={"Img1"}
          />
          <img
            id={"img2"}
            src={Butterfly2}
            onClick={
              (event) => {
                takePicture(event);
                DrawPicture();
                setPointsId(elements.length)
              }
            }
            style={{ cursor: "pointer" }}
            alt={"Img2"}
          />
            <img
            id={"img3"}
            src={Butterfly3}
            onClick={
              (event) => {
                takePicture(event);
                DrawPicture();
                setPointsId(elements.length)
              }
            }
            style={{ cursor: "pointer" }}
            alt={"img3"}
          />
          </div>
<canvas
            onMouseDown={startDrawing}
            onMouseUp={endDrawing}
            onMouseMove={draw}
            onMouseLeave={endDrawing}
            ref={canvasRef}
            width={width}
            height={window.innerHeight}
          />
        </div>

my functions codes :

function takePicture(event) {
    setImgSRC(event.target.src);
  }
  function DrawPicture() {
   
    var Se_image = new Image();
    Se_image.onload = start;
    Se_image.src = ImgSRC;
  
    Se_image.onerror = function(){ alert(Se_image.src+"failed to load") }
    function start() {
      ctxRef.current.drawImage(Se_image, POx1, POY1, widthSize, heightSize);
    }
  }

the POx1, POY1, widthSize, heightSize that variable There are variable that I already received .

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!