This article shares the specific code of JavaScript canvas to load pictures for your reference. The specific content is as follows Code: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Using image</title> <style type="text/css"> * { /* margin: 0; padding: 0; */ box-sizing: border-box; } canvas { border-width: 1px; border-color: #000000; border-style: solid; } </style> </head> <body> <canvas id="canvas"></canvas> <div> <input type="file" accept="image/*" /> </div> <script type="text/javascript"> window.onload = (event) => { main() } function main() { const canvas = document.getElementById("canvas"); const ctx = canvas.getContext("2d"); const inputFile = document.querySelector("input[type=file]"); inputFile.onchange = (event) => { const files = event.target.files; if (files.length > 0) { const file = files[0]; // First file console.log(file); const image = new Image(); image.src = URL.createObjectURL(file); image.onload = function(event) { // console.log(event, this); URL.revokeObjectURL(this.src); canvas.width = image.width; canvas.height = image.height; ctx.drawImage(image, 0, 0); } } } } </script> </body> </html> Reference: Link The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Introduction to ufw firewall in Linux
Table of contents Multiple conditional statements...
:is dynamic component Use v-bind:is="compone...
<br />In HTML language, you can automaticall...
Table of contents 1. Event delegation Event Bubbl...
This article example shares the specific code of ...
Classical color combinations convey power and auth...
mktemp Create temporary files or directories in a...
Suggestion: Handwriting code as much as possible c...
Preface: Recently, the company project changed th...
Table of contents environment summary Module Func...
Vue data two-way binding principle, but this meth...
Table of contents 1. Joint index description 2. C...
Table of contents 1. Setup 1. The first parameter...
In this article, I will explain in detail how to ...
After this roll call device starts calling the ro...