zoukankan      html  css  js  c++  java
  • 读取文件/文件夹并回显

    </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 storage 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>
    </html>
    
    <body>
    
    <input type="file" onchange="previewFile()"><br>
    <img src="" height="200" alt="Image preview...">
    <script>
        // 加载图片并并回显
        function previewFile() {
            // Where you will display your image
            var preview = document.querySelector('img');
            // The button where the user chooses the local image to display
            var file = document.querySelector('input[type=file]').files[0];
            // FileReader instance
            var reader = new FileReader();
    
            // When the image is loaded we will set it as source of
            // our img tag
            reader.onloadend = function () {
                preview.src = reader.result;
            }
    
    
            if (file) {
                // Load image as a base64 encoded URI
                reader.readAsDataURL(file);
            } else {
                preview.src = "";
            }
        }
    </script>
    
    
    </body>
    
  • 相关阅读:
    ORACLE中的TOP-N查询(TOP-N分析)、分页查询
    ORACLE复杂查询之子查询
    ORACLE复杂查询之连接查询
    利用rand7() 产生rand10()(腾讯)
    汉罗塔1(递归和分治)
    数位dp(不要62)
    数位dp(二进制01问题)
    多重背包
    模拟(所有边权)
    模拟(进制)
  • 原文地址:https://www.cnblogs.com/bbdbolg/p/14691384.html
Copyright © 2011-2022 走看看