canvas - how to RESET rectangle area when creating new on image? The 2019 Stack Overflow Developer Survey Results Are InHow to draw a rounded Rectangle on HTML Canvas?How to clear the canvas for redrawingResizing an image in an HTML5 canvasHow to produce such page flip effects in Canvas?How to add image to canvasDisable Interpolation when Scaling a <canvas>Canvas and SharePoint dropdown menu conflict in ChromeHow To Save Canvas As An Image With canvas.toDataURL()?JS Boolean var doesn't affect if-statementsHow to fix this “mouse hover” function in a canvas
What's the name of these plastic connectors
Can you cast a spell on someone in the Ethereal Plane, if you are on the Material Plane and have the True Seeing spell active?
Is bread bad for ducks?
Slides for 30 min~1 hr Skype tenure track application interview
How do you keep chess fun when your opponent constantly beats you?
What is this business jet?
Relationship between Gromov-Witten and Taubes' Gromov invariant
Ubuntu Server install with full GUI
Inverse Relationship Between Precision and Recall
Button changing its text & action. Good or terrible?
How to translate "being like"?
What is the most efficient way to store a numeric range?
Match Roman Numerals
Does adding complexity mean a more secure cipher?
"as much details as you can remember"
Keeping a retro style to sci-fi spaceships?
Why “相同意思的词” is called “同义词” instead of "同意词"?
For what reasons would an animal species NOT cross a *horizontal* land bridge?
Can I have a signal generator on while it's not connected?
Cooking pasta in a water boiler
How to notate time signature switching consistently every measure
A word that means fill it to the required quantity
Likelihood that a superbug or lethal virus could come from a landfill
Geography at the pixel level
canvas - how to RESET rectangle area when creating new on image?
The 2019 Stack Overflow Developer Survey Results Are InHow to draw a rounded Rectangle on HTML Canvas?How to clear the canvas for redrawingResizing an image in an HTML5 canvasHow to produce such page flip effects in Canvas?How to add image to canvasDisable Interpolation when Scaling a <canvas>Canvas and SharePoint dropdown menu conflict in ChromeHow To Save Canvas As An Image With canvas.toDataURL()?JS Boolean var doesn't affect if-statementsHow to fix this “mouse hover” function in a canvas
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Can anyone help me for this please ?
Main requirement : How to clear previous rectangle areas when creating new one on image?
If above requirement resolved then it will be great, other than that is it possible to do following ?
a) Is it possible to resize rectangle after drawing it?
b) Is it possible to move rectangle possiton which was created
"use strict";
requestAnimationFrame(mainLoop);
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
const storedRects = [];
const baseImage = loadImage("https://www.w3schools.com/css/img_fjords.jpg");
var refresh = true;
const rect = (() =>
var x1, y1, x2, y2;
var show = false;
function fix()
rect.x = Math.min(x1, x2);
rect.y = Math.min(y1, y2);
rect.w = Math.max(x1, x2) - Math.min(x1, x2);
rect.h = Math.max(y1, y2) - Math.min(y1, y2);
function draw(ctx)
ctx.strokeRect(this.x, this.y, this.w, this.h)
const rect = x : 0, y : 0, w : 0, h : 0, draw;
const API =
restart(point)
x2 = x1 = point.x;
y2 = y1 = point.y;
fix();
show = true;
,
update(point)
x2 = point.x;
y2 = point.y;
fix();
show = true;
,
toRect()
show = false;
return Object.assign(, rect);
,
draw(ctx)
if (show) rect.draw(ctx)
,
show : false,
return API;
)();
function loadImage(url)
const image = new Image();
image.src = url;
image.onload = () => refresh = true;
return image;
const mouse =
button : false,
x : 0,
y : 0,
down : false,
up : false,
element : null,
event(e)
const m = mouse;
m.bounds = m.element.getBoundingClientRect();
m.x = e.pageX - m.bounds.left - scrollX;
m.y = e.pageY - m.bounds.top - scrollY;
const prevButton = m.button;
m.button = e.type === "mousedown" ? true : e.type === "mouseup" ? false : mouse.button;
if (!prevButton && m.button) m.down = true
if (prevButton && !m.button) m.up = true
,
start(element)
mouse.element = element;
"down,up,move".split(",").forEach(name => document.addEventListener("mouse" + name, mouse.event));
mouse.start(canvas);
function draw()
ctx.drawImage(baseImage, 0, 0, ctx.canvas.width, ctx.canvas.width);
ctx.lineWidth = 1;
ctx.strokeStyle = "yellow";
storedRects.forEach(rect => rect.draw(ctx));
ctx.strokeStyle = "red";
rect.draw(ctx);
function mainLoop()
if (refresh
<canvas id="myCanvas" width="800" height="500" title = "click and drag to add rectangles" style="border:1px solid #000000;cursor:crosshair"></canvas>
html5 canvas
add a comment |
Can anyone help me for this please ?
Main requirement : How to clear previous rectangle areas when creating new one on image?
If above requirement resolved then it will be great, other than that is it possible to do following ?
a) Is it possible to resize rectangle after drawing it?
b) Is it possible to move rectangle possiton which was created
"use strict";
requestAnimationFrame(mainLoop);
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
const storedRects = [];
const baseImage = loadImage("https://www.w3schools.com/css/img_fjords.jpg");
var refresh = true;
const rect = (() =>
var x1, y1, x2, y2;
var show = false;
function fix()
rect.x = Math.min(x1, x2);
rect.y = Math.min(y1, y2);
rect.w = Math.max(x1, x2) - Math.min(x1, x2);
rect.h = Math.max(y1, y2) - Math.min(y1, y2);
function draw(ctx)
ctx.strokeRect(this.x, this.y, this.w, this.h)
const rect = x : 0, y : 0, w : 0, h : 0, draw;
const API =
restart(point)
x2 = x1 = point.x;
y2 = y1 = point.y;
fix();
show = true;
,
update(point)
x2 = point.x;
y2 = point.y;
fix();
show = true;
,
toRect()
show = false;
return Object.assign(, rect);
,
draw(ctx)
if (show) rect.draw(ctx)
,
show : false,
return API;
)();
function loadImage(url)
const image = new Image();
image.src = url;
image.onload = () => refresh = true;
return image;
const mouse =
button : false,
x : 0,
y : 0,
down : false,
up : false,
element : null,
event(e)
const m = mouse;
m.bounds = m.element.getBoundingClientRect();
m.x = e.pageX - m.bounds.left - scrollX;
m.y = e.pageY - m.bounds.top - scrollY;
const prevButton = m.button;
m.button = e.type === "mousedown" ? true : e.type === "mouseup" ? false : mouse.button;
if (!prevButton && m.button) m.down = true
if (prevButton && !m.button) m.up = true
,
start(element)
mouse.element = element;
"down,up,move".split(",").forEach(name => document.addEventListener("mouse" + name, mouse.event));
mouse.start(canvas);
function draw()
ctx.drawImage(baseImage, 0, 0, ctx.canvas.width, ctx.canvas.width);
ctx.lineWidth = 1;
ctx.strokeStyle = "yellow";
storedRects.forEach(rect => rect.draw(ctx));
ctx.strokeStyle = "red";
rect.draw(ctx);
function mainLoop()
if (refresh
<canvas id="myCanvas" width="800" height="500" title = "click and drag to add rectangles" style="border:1px solid #000000;cursor:crosshair"></canvas>
html5 canvas
add a comment |
Can anyone help me for this please ?
Main requirement : How to clear previous rectangle areas when creating new one on image?
If above requirement resolved then it will be great, other than that is it possible to do following ?
a) Is it possible to resize rectangle after drawing it?
b) Is it possible to move rectangle possiton which was created
"use strict";
requestAnimationFrame(mainLoop);
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
const storedRects = [];
const baseImage = loadImage("https://www.w3schools.com/css/img_fjords.jpg");
var refresh = true;
const rect = (() =>
var x1, y1, x2, y2;
var show = false;
function fix()
rect.x = Math.min(x1, x2);
rect.y = Math.min(y1, y2);
rect.w = Math.max(x1, x2) - Math.min(x1, x2);
rect.h = Math.max(y1, y2) - Math.min(y1, y2);
function draw(ctx)
ctx.strokeRect(this.x, this.y, this.w, this.h)
const rect = x : 0, y : 0, w : 0, h : 0, draw;
const API =
restart(point)
x2 = x1 = point.x;
y2 = y1 = point.y;
fix();
show = true;
,
update(point)
x2 = point.x;
y2 = point.y;
fix();
show = true;
,
toRect()
show = false;
return Object.assign(, rect);
,
draw(ctx)
if (show) rect.draw(ctx)
,
show : false,
return API;
)();
function loadImage(url)
const image = new Image();
image.src = url;
image.onload = () => refresh = true;
return image;
const mouse =
button : false,
x : 0,
y : 0,
down : false,
up : false,
element : null,
event(e)
const m = mouse;
m.bounds = m.element.getBoundingClientRect();
m.x = e.pageX - m.bounds.left - scrollX;
m.y = e.pageY - m.bounds.top - scrollY;
const prevButton = m.button;
m.button = e.type === "mousedown" ? true : e.type === "mouseup" ? false : mouse.button;
if (!prevButton && m.button) m.down = true
if (prevButton && !m.button) m.up = true
,
start(element)
mouse.element = element;
"down,up,move".split(",").forEach(name => document.addEventListener("mouse" + name, mouse.event));
mouse.start(canvas);
function draw()
ctx.drawImage(baseImage, 0, 0, ctx.canvas.width, ctx.canvas.width);
ctx.lineWidth = 1;
ctx.strokeStyle = "yellow";
storedRects.forEach(rect => rect.draw(ctx));
ctx.strokeStyle = "red";
rect.draw(ctx);
function mainLoop()
if (refresh
<canvas id="myCanvas" width="800" height="500" title = "click and drag to add rectangles" style="border:1px solid #000000;cursor:crosshair"></canvas>
html5 canvas
Can anyone help me for this please ?
Main requirement : How to clear previous rectangle areas when creating new one on image?
If above requirement resolved then it will be great, other than that is it possible to do following ?
a) Is it possible to resize rectangle after drawing it?
b) Is it possible to move rectangle possiton which was created
"use strict";
requestAnimationFrame(mainLoop);
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
const storedRects = [];
const baseImage = loadImage("https://www.w3schools.com/css/img_fjords.jpg");
var refresh = true;
const rect = (() =>
var x1, y1, x2, y2;
var show = false;
function fix()
rect.x = Math.min(x1, x2);
rect.y = Math.min(y1, y2);
rect.w = Math.max(x1, x2) - Math.min(x1, x2);
rect.h = Math.max(y1, y2) - Math.min(y1, y2);
function draw(ctx)
ctx.strokeRect(this.x, this.y, this.w, this.h)
const rect = x : 0, y : 0, w : 0, h : 0, draw;
const API =
restart(point)
x2 = x1 = point.x;
y2 = y1 = point.y;
fix();
show = true;
,
update(point)
x2 = point.x;
y2 = point.y;
fix();
show = true;
,
toRect()
show = false;
return Object.assign(, rect);
,
draw(ctx)
if (show) rect.draw(ctx)
,
show : false,
return API;
)();
function loadImage(url)
const image = new Image();
image.src = url;
image.onload = () => refresh = true;
return image;
const mouse =
button : false,
x : 0,
y : 0,
down : false,
up : false,
element : null,
event(e)
const m = mouse;
m.bounds = m.element.getBoundingClientRect();
m.x = e.pageX - m.bounds.left - scrollX;
m.y = e.pageY - m.bounds.top - scrollY;
const prevButton = m.button;
m.button = e.type === "mousedown" ? true : e.type === "mouseup" ? false : mouse.button;
if (!prevButton && m.button) m.down = true
if (prevButton && !m.button) m.up = true
,
start(element)
mouse.element = element;
"down,up,move".split(",").forEach(name => document.addEventListener("mouse" + name, mouse.event));
mouse.start(canvas);
function draw()
ctx.drawImage(baseImage, 0, 0, ctx.canvas.width, ctx.canvas.width);
ctx.lineWidth = 1;
ctx.strokeStyle = "yellow";
storedRects.forEach(rect => rect.draw(ctx));
ctx.strokeStyle = "red";
rect.draw(ctx);
function mainLoop()
if (refresh
<canvas id="myCanvas" width="800" height="500" title = "click and drag to add rectangles" style="border:1px solid #000000;cursor:crosshair"></canvas>
"use strict";
requestAnimationFrame(mainLoop);
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
const storedRects = [];
const baseImage = loadImage("https://www.w3schools.com/css/img_fjords.jpg");
var refresh = true;
const rect = (() =>
var x1, y1, x2, y2;
var show = false;
function fix()
rect.x = Math.min(x1, x2);
rect.y = Math.min(y1, y2);
rect.w = Math.max(x1, x2) - Math.min(x1, x2);
rect.h = Math.max(y1, y2) - Math.min(y1, y2);
function draw(ctx)
ctx.strokeRect(this.x, this.y, this.w, this.h)
const rect = x : 0, y : 0, w : 0, h : 0, draw;
const API =
restart(point)
x2 = x1 = point.x;
y2 = y1 = point.y;
fix();
show = true;
,
update(point)
x2 = point.x;
y2 = point.y;
fix();
show = true;
,
toRect()
show = false;
return Object.assign(, rect);
,
draw(ctx)
if (show) rect.draw(ctx)
,
show : false,
return API;
)();
function loadImage(url)
const image = new Image();
image.src = url;
image.onload = () => refresh = true;
return image;
const mouse =
button : false,
x : 0,
y : 0,
down : false,
up : false,
element : null,
event(e)
const m = mouse;
m.bounds = m.element.getBoundingClientRect();
m.x = e.pageX - m.bounds.left - scrollX;
m.y = e.pageY - m.bounds.top - scrollY;
const prevButton = m.button;
m.button = e.type === "mousedown" ? true : e.type === "mouseup" ? false : mouse.button;
if (!prevButton && m.button) m.down = true
if (prevButton && !m.button) m.up = true
,
start(element)
mouse.element = element;
"down,up,move".split(",").forEach(name => document.addEventListener("mouse" + name, mouse.event));
mouse.start(canvas);
function draw()
ctx.drawImage(baseImage, 0, 0, ctx.canvas.width, ctx.canvas.width);
ctx.lineWidth = 1;
ctx.strokeStyle = "yellow";
storedRects.forEach(rect => rect.draw(ctx));
ctx.strokeStyle = "red";
rect.draw(ctx);
function mainLoop()
if (refresh
<canvas id="myCanvas" width="800" height="500" title = "click and drag to add rectangles" style="border:1px solid #000000;cursor:crosshair"></canvas>
"use strict";
requestAnimationFrame(mainLoop);
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
const storedRects = [];
const baseImage = loadImage("https://www.w3schools.com/css/img_fjords.jpg");
var refresh = true;
const rect = (() =>
var x1, y1, x2, y2;
var show = false;
function fix()
rect.x = Math.min(x1, x2);
rect.y = Math.min(y1, y2);
rect.w = Math.max(x1, x2) - Math.min(x1, x2);
rect.h = Math.max(y1, y2) - Math.min(y1, y2);
function draw(ctx)
ctx.strokeRect(this.x, this.y, this.w, this.h)
const rect = x : 0, y : 0, w : 0, h : 0, draw;
const API =
restart(point)
x2 = x1 = point.x;
y2 = y1 = point.y;
fix();
show = true;
,
update(point)
x2 = point.x;
y2 = point.y;
fix();
show = true;
,
toRect()
show = false;
return Object.assign(, rect);
,
draw(ctx)
if (show) rect.draw(ctx)
,
show : false,
return API;
)();
function loadImage(url)
const image = new Image();
image.src = url;
image.onload = () => refresh = true;
return image;
const mouse =
button : false,
x : 0,
y : 0,
down : false,
up : false,
element : null,
event(e)
const m = mouse;
m.bounds = m.element.getBoundingClientRect();
m.x = e.pageX - m.bounds.left - scrollX;
m.y = e.pageY - m.bounds.top - scrollY;
const prevButton = m.button;
m.button = e.type === "mousedown" ? true : e.type === "mouseup" ? false : mouse.button;
if (!prevButton && m.button) m.down = true
if (prevButton && !m.button) m.up = true
,
start(element)
mouse.element = element;
"down,up,move".split(",").forEach(name => document.addEventListener("mouse" + name, mouse.event));
mouse.start(canvas);
function draw()
ctx.drawImage(baseImage, 0, 0, ctx.canvas.width, ctx.canvas.width);
ctx.lineWidth = 1;
ctx.strokeStyle = "yellow";
storedRects.forEach(rect => rect.draw(ctx));
ctx.strokeStyle = "red";
rect.draw(ctx);
function mainLoop()
if (refresh
<canvas id="myCanvas" width="800" height="500" title = "click and drag to add rectangles" style="border:1px solid #000000;cursor:crosshair"></canvas>
html5 canvas
html5 canvas
asked Mar 8 at 10:49
ViralViral
199116
199116
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55061605%2fcanvas-how-to-reset-rectangle-area-when-creating-new-on-image%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55061605%2fcanvas-how-to-reset-rectangle-area-when-creating-new-on-image%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown