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
Achieve resultsImplementation Code html <div&g...
The following code is in my test.html. The video c...
1. CSS3 triangle continues to zoom in special eff...
CocosCreator version: 2.3.4 Most games have layer...
When doing DIV+CSS layout of the page, it is very...
1. Introduction: If we want to display flash conte...
Hexo binds a custom domain name to GitHub under W...
Table of contents plan Install Dependencies Intro...
When encapsulating Vue components, I will still u...
Table of contents 1. Achieve results 2. Implement...
Preface Vue (pronounced /vjuː/, similar to view) ...
Problem Description Install nginx on Tencent Clou...
Performance For example: HTML: <div class=&quo...
Panther started as a rookie, and I am still a roo...
Table of contents Effect display Component Settin...