zoukankan      html  css  js  c++  java
  • 获取图片大小 包括长宽和质量大小

    长宽获取(此方法只在网络加载图片,且未知其大小前需要控制时使用)

    				 image.src=PATH;//图片路径,以下都是判断浏览器,然后获取大小,也就是我们常做的预加载图片。
    				 var userAgent = navigator.userAgent.toLowerCase();
    				 var kmki="";
    				 if(navigator.userAgent.indexOf("MSIE")>0){
    					 kmki="0";
    				 }
    				 console.log(userAgent);
    				 if(kmki=="0"){
    					 if($.browser.version==6.0){
    						 image.onreadystatechange = function () {
    							 if (image.readyState == "complete"){
    								  //var logw=image.width,logh=image.height;
    							       ak(image.width,image.height)
    //IE6,7,8获取图片质量大小开源用image.fileSize } }; }else{ ie7imagetime = window.setInterval(function(){ var rs = image.readyState; if(rs=="complete"){ window.clearInterval(ie7imagetime); //var logw=image.width,logh=image.height; ak(image.width,image.height)
    //IE6,7,8获取图片质量大小开源用image.fileSize }else{ return; } },200); } }else{ image.onload = function () { if (image.complete == true){ //var logw=image.width,logh=image.height; ak(image.width,image.height) } }; }

    获取质量大小

    <input type="button" value="GET Size" onclick="getFileSize(document.getElementById('xx'))" />
      <img src="a.jpg" id="xx" alt="" />
      <script>
        function getFileSize(o) {
          x = window.XMLHttpRequest ? new window.XMLHttpRequest : new ActiveXObject("MSxml2.XMLHTTP");
          x.open("HEAD", o.src, false);
          x.send();
          alert("大小:" + x.getResponseHeader("Content-Length"));
        }
    </script>

    此方法需要开ActiveX控件
  • 相关阅读:
    应用实例-最大子列和问题
    什么是算法
    什么是数据结构
    数据结构与算法-Python/C(目录)
    collections模块
    色彩缤纷的Python(改变字体颜色及样式)
    取数组中一段值的算法(转)
    开发者必备,超实用的PHP代码片段(转)
    php中数组自定义排序
    rand值出现负数的解决方案
  • 原文地址:https://www.cnblogs.com/dean5277/p/2637661.html
Copyright © 2011-2022 走看看