zoukankan      html  css  js  c++  java
  • 使用File, FormData将图片的blob数据进行图片旋转然后上传操作

    if (this.currentImg && this.currentImg.path) {
    this.rotateNum++;
    let degree = 0;
    let rotateInput = this.rotateNum * 90;
    degree += parseInt(rotateInput);
    degree %= 360;
    let img = new Image();
    img.setAttribute("crossOrigin",'Anonymous');
    img.src = this.currentImg.path;
    img.onload = () => {
    let $w = img.width, $h = img.height, $c = document.getElementById("uploadImageCanvas");
    let ctx = $c.getContext("2d");
    if (degree === 90) {
    $c.width = $h;
    $c.height = $w;
    ctx.clearRect(0, 0, $h, $w);
    ctx.rotate(degree / 180 * Math.PI);
    ctx.translate(0, -$h);
    ctx.drawImage(img, 0, 0);
    } else if (degree === 270) {
    $c.width = $h;
    $c.height = $w;
    ctx.clearRect(0, 0, $h, $w);
    ctx.rotate(degree / 180 * Math.PI);
    ctx.translate(-$w, 0);
    ctx.drawImage(img, 0, 0);
    } else {
    $c.width = $w;
    $c.height = $h;
    ctx.clearRect(0, 0, $w, $h);
    ctx.translate($w / 2, $h / 2);
    ctx.rotate(degree / 180 * Math.PI);
    ctx.translate(-$w / 2, -$h / 2);
    ctx.drawImage(img, $w / 2 - $w / 2, $h / 2 - $h / 2);
    }
    $c.toBlob((blob) => {
    let fd = new FormData();
    let fileBlob = new File([blob], new Date().getTime() + '.png')
    fd.append("file", fileBlob);
    CommonPOSThandUpload(fd).then((response) => {
    if (response && response.data) {
    let oRes = response.data;
    if (oRes) {
    this.setImgUid(oRes);
    }
    }
    })
    });
    }
    } else {
    this.rotateNum = 0;
    }
  • 相关阅读:
    查找算法(I) 顺序查找 二分查找 索引查找
    快速排序 Quick Sort
    Activity生命周期
    Android中资源文件的使用
    排序算法
    插入排序(I)Insert Sort
    Java eclipse调试技巧什么的。。
    HTTP协议解析
    python技巧26[str+unicode+codecs]
    python类库26[PySide之helloworld]
  • 原文地址:https://www.cnblogs.com/hsdying/p/14452472.html
Copyright © 2011-2022 走看看