I need to load a server side image into a user defined 'frame' with straight js on canvas element-

StackOverflow https://stackoverflow.com/questions/15537873

  •  24-03-2022
  •  | 
  •  

문제

I have a canvas that allows the user to stroke a rectangle - I need this newly drawn rectangle to become the destination coords for an image coming in from db

Im hoping that one of you javaScript jedi's would quickly high-level outline or pseudo-code the most logical approach to my padawan problem. 'Help Me [your name here], You're my only hope.' Im stopping now.

도움이 되었습니까?

해결책

The way I handled this was to use the mouse event handlers rect.startX & rect.startY for the destination (x,y) and the rect.width & rect.height at the destination w/h:

document.getElementById("image").onclick= function() {
    context.drawImage(image,rect.startX,rect.startY,rect.w,rect.h);
};

The images from the server are handled in a 'image-prepper' function that loads the images onto an offscreen canvas where they reside until called onto the visible canvas.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top