How can I prevent the stroke on Canvas to stop from breaking
Zoom into the below image with (mouse scroll)
pixels break on the black rectangle drawn
Edit : adding lineWidth/2
pixels to start coordinates fixes the problem
// grab the DOM SVG element that you want to be draggable/zoomable:
const element = document.getElementById('scene');
// and forward it it to panzoom.
panzoom(element);
const c = document.getElementById("myCanvas");
const ctx = c.getContext("2d");
ctx.strokeRect(20.5, 20.5, 150, 100);
.imageContainer {
overflow: hidden;
border: 3px solid red;
height: 300px;
margin: 0 auto
}
img {
display: table;
margin: 0 auto;
height: 300px;
}
canvas {
display: table;
margin: 0 auto;
height: 300px;
width: 533px;
border: 1px solid gold;
z-index: 2;
position: absolute;
top: 0;
left: 126px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://unpkg.com/panzoom@8.1.0/dist/panzoom.min.js"></script>
<body>
<div class='imageContainer '>
<div id="scene">
<img id='imageHD' src="https://cdn.wallpapersafari.com/57/46/dY3eN1.jpg">
<canvas id='myCanvas'></canvas>
</div>
</div>
</body>