One purpose Select a local folder on the Html page to automatically read all the images in the folder and its subfolders and display them on the page. Technical Analysis: Problems
Solution: Call the readAsDataURL method in the Web API interface FileReader to read the data (the file path obtained by the function parameter file tag), and then load the data into FileReader (base64 format). After that, you can use Img to specify the source data in base64 format and draw pictures. Second code <!DOCTYPE html> <html> <head> <title>ReadImageDemo</title> </head> <body> <input type="file" id="selectFiles" onchange="dealSelectFiles()" multiple webkitdirectory> <canvas id="myCanvas" width=1440 height=900></canvas> <script type="text/javascript"> var imgPosX = 0; var imgWidth = 256; function dealSelectFiles(){ /// get select files. var selectFiles = document.getElementById("selectFiles").files; for(var file of selectFiles){ console.log(file.webkitRelativePath); /// read file content. var reader = new FileReader(); reader.readAsDataURL(file); reader.onloadend = function(){ /// deal data. var img = new Image(); /// After loader, result stores the file content result. img.src = this.result; img.onload = function(){ var myCanvas = document.getElementById("myCanvas"); var cxt = myCanvas.getContext('2d'); cxt.drawImage(img, imgPosX, 0); imgPosX += imgWidth; } } } } </script> </body> </html> Three effects 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. |
<<: Commonly used js function methods in the front end
>>: Detailed explanation of scp and sftp commands under Linux
Specific method: First open the command prompt; T...
1. Introduction Earlier we talked about the front...
Error message: ERROR 2002: Can't connect to l...
When I first used docker, I didn't use docker...
Using NULL in comparison operators mysql> sele...
What to do if you forget Windows Server 2008R2 So...
Table of contents 1. Introduction to ReactJS 2. U...
Table of contents 1. Current limiting algorithm 2...
Today I am a little confused about <a href=&quo...
This article shares with you the Ubuntu server ve...
This article describes how to use docker to deplo...
Building new images from existing images is done ...
What is HTML? HTML is a language used to describe...
Downloaded an es image from docker hub, version 6...
Main library configuration 1. Configure mysql vim...