0
点赞
收藏
分享

微信扫一扫

零基础学习JS--基础篇--使用对象

幺幺零 2024-03-12 阅读 12

这类iphone中手机竖着拿然后逆时针旋转90°才是正确的拍照姿势

这时候拍出来的照片展示在canvas中是不会被旋转的。如果以其他角度拍照时,就会发生旋转。

function imgToCanvasWithOrientation(img, width, height, orientation) {
    let canvas = document.createElement("canvas");
    let ctx = canvas.getContext("2d");
    canvas.width=width
    canvas.height=height
    if (判断机型系统不高于ios13.4.1) {
        switch (orientation) {
            case 3:
                ctx.rotate(Math.PI)
                ctx.drawImage(img, -width, -height, width, height);
                break;
            case 6:
                ctx.rotate(0.5 * Math.PI)
                ctx.drawImage(img, 0, -height, width, height);
                break;
            case 8:
                ctx.rotate(3 * Math.PI / 2)
                ctx.drawImage(img, -width, 0, width, height);
                break;
            default:
                ctx.drawImage(img, 0, 0, width, height);
                break
        }
    }
    
    return canvas.toDataURL(“image/png”);
}
举报

相关推荐

0 条评论