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
Create a folder Directory structure: dabaots Init...
Table of contents Throttling and anti-shake conce...
This article mainly introduces how to specify par...
This article uses examples to illustrate the impa...
Table of contents 1. The default focus is on the ...
1.vue packaging Here we use the vue native packag...
This article will not explain the use and install...
view What is a view? What is the role of a view? ...
Preface This article uses the new features of MyS...
This article example shares the specific code of ...
Preface Whether it is a stand-alone lock or a dis...
Since the team is separating the front-end and ba...
Source code preview: https://github.com/jdf2e/nut...
This article shares the specific code of the jQue...
Apache Superset is a powerful BI tool that provid...