JavaScript canvas - how to select multi rectangle area on image?

var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var rect = {};
var drag = false;
make_base();
init();


function make_base() {
  base_image = new Image();
  base_image.src = 'https://www.w3schools.com/css/img_fjords.jpg';
  base_image.onload = function() {
    context.drawImage(base_image, 0, 0, 800, 500);
  }
}

function writeMessage(canvas, message) {
  var context = canvas.getContext('2d');
  context.clearRect(0, 0, canvas.width, canvas.height);
  context.drawImage(base_image, 0, 0, 800, 500);
  context.font = '12pt Calibri';
  context.fillStyle = 'red';
  context.fillText(message, 25, 25);
}

function getMousePos(canvas, evt) {
  var rect = canvas.getBoundingClientRect();
  return {
    x: evt.clientX - rect.left,
    y: evt.clientY - rect.top
  };
}

function init() {

    canvas.addEventListener('mousedown', mouseDown, false);
    canvas.addEventListener('mouseup', mouseUp, false);
    canvas.addEventListener('mousemove', mouseMove, false);
}

function mouseDown(e) {
    rect.startX = e.pageX - this.offsetLeft;
    rect.startY = e.pageY - this.offsetTop;
    drag = true;
}

function mouseUp() {
    drag = false;
}

function mouseMove(e) {
    if(drag) {
        rect.w = (e.pageX - this.offsetLeft) - rect.startX;
        rect.h = (e.pageY - this.offsetTop) - rect.startY ;
        context.clearRect(rect.startX, rect.startY, rect.w, rect.h);
        draw();
    }
}

function draw() {
    context.lineWidth="1";
    context.strokeStyle = "blue";
    context.beginPath();
    context.rect(rect.startX, rect.startY, rect.w, rect.h);
    context.stroke();
    context.closePath();
}
<canvas id="myCanvas" width="800" height="500" style="border:1px solid #000000;">
    </canvas>
Answer:1

I have this code <span id="signinButton" class="g-signin" data-callback="signinCallback" data-clientid="...

I have this code <span id="signinButton" class="g-signin" data-callback="signinCallback" data-clientid="...

I am using qrcode.js for generating qrcode. I want to generate random QR code every time I click into add new tab instead of add new qr code. I created a code for a random number but when I try to add ...

I am using qrcode.js for generating qrcode. I want to generate random QR code every time I click into add new tab instead of add new qr code. I created a code for a random number but when I try to add ...

  1. generate random code javascript
  2. generate random code python
  3. generate random code in excel
  4. generate random code php
  5. generate random code c#
  6. generate random code java
  7. generate random code laravel
  8. generate random code online
  9. generate random code nodejs
  10. generate random code
  11. generate random code sql server
  12. generate random code sql
  13. generate random code in codeigniter
  14. generate random code vb.net
  15. generate random code numbers
  16. generate random code in swift
  17. generate random code string
  18. generate random qr code
  19. generate random color code in javascript
  20. generate random zip code

I have a problem with my code it has a running error I am trying to convert an object to an array list. In my code, I was trying to build an array inside an array! I was expecting to have a return ...

I have a problem with my code it has a running error I am trying to convert an object to an array list. In my code, I was trying to build an array inside an array! I was expecting to have a return ...

  1. convert object array to string array
  2. convert object array to int array
  3. convert object array to list
  4. convert object array to string array c#
  5. convert object array to string array java
  6. convert object array to string array javascript
  7. convert object array to list c#
  8. convert object array to string array powershell
  9. convert object array to array javascript
  10. convert object array to json javascript
  11. convert object array to int array c#
  12. convert object array to double array java
  13. convert object array to float array python
  14. convert object array to arraylist java
  15. convert object array to byte array c#
  16. convert object array to string array python
  17. convert object array to json java
  18. convert object array to primitive array java
  19. convert object array to string array typescript
  20. convert object array to char array in java

I have a react project that uses messaging, so I want the most recently added message to be displayed on the bottom. I've tried the 'reversed' property for HTML5 tags, but it doesn't seem to change ...

I have a react project that uses messaging, so I want the most recently added message to be displayed on the bottom. I've tried the 'reversed' property for HTML5 tags, but it doesn't seem to change ...

  1. reverse display order
  2. display flex reverse order
  3. display grid reverse order
  4. extend display reverse order
  5. display in reverse order python
  6. display array in reverse order java
  7. display string in reverse order java
  8. display array in reverse order
  9. display array in reverse order c++
  10. display array in reverse order javascript
  11. display inline-block reverse order
  12. display string in reverse order python
  13. display numbers in reverse order c++
  14. display string in reverse order c++
  15. display numbers in reverse order java
  16. display listview in reverse order
  17. display file in reverse order unix
  18. display string in reverse order
  19. display li in reverse order
  20. display vector in reverse order c++