zoukankan      html  css  js  c++  java
  • 拍照上传图片方向调整

    解决某些手机系统正方向竖着拍方向错乱的问题。

    npm install exif-js --save
    import EXIF from "exif-js";
          let reader = new FileReader();
          reader.readAsDataURL(file);
          if (file) {
            EXIF.getData(file, function() {
              let ori = EXIF.getTag(this, "Orientation");
              // alert(ori, "手持方向");
              reader.onload = ev => {
                let image = new Image();
                image.src = ev.target.result;
                image.onload = () => {
                  let canvas = document.createElement("canvas"),
                    ctx = canvas.getContext("2d");
                  if (ori == 6 && image.width > image.height) {
                    //ios正方向竖着排方向错乱时,旋转90度
                    canvas.width = image.height;
                    canvas.height = image.width;
                    ctx.rotate(Math.PI / 2);
                    ctx.drawImage(image, 0, -image.height, image.width, image.height);
                  } else {
                    canvas.width = image.width / 2;
                    canvas.height = image.height / 2;
                    ctx.drawImage(image, 0, 0, image.width / 2, image.height / 2);
                  }
                  resolve(canvas.toDataURL("image/jpeg"));
                };
              };
            });
          }
  • 相关阅读:
    Map
    Enumeration输出
    iterator的基本用法
    Annotation整合工厂设计模式
    自定义Annotation
    Annotation
    动态代理设计模式
    静态代理设计模式
    自定义ClassLoader
    获取类的类对象的几种方式
  • 原文地址:https://www.cnblogs.com/kongwei/p/13209821.html
Copyright © 2011-2022 走看看