android 点击图片旋转90度,iphone上传拍照图片时图片会旋转90度,从相册选择就不会,安卓手机也不会,怎么解决?...

之前也遇到过这个问题,到stackoverflow上搜到了这个答案(IE10+):

function getOrientation(file, callback) {

var reader = new FileReader();

reader.onload = function(e) {

var view = new DataView(e.target.result);

if (view.getUint16(0, false) != 0xFFD8) return callback(-2);

var length = view.byteLength, offset = 2;

while (offset < length) {

var marker = view.getUint16(offset, false);

offset += 2;

if (marker == 0xFFE1) {

if (view.getUint32(offset += 2, false) != 0x45786966) return callback(-1);

var little = view.getUint16(offset += 6, false) == 0x4949;

offset += view.getUint32(offset + 4, little);

var tags = view.getUint16(offset, little);

offset += 2;

for (var i = 0; i < tags; i++)

if (view.getUint16(offset + (i * 12), little) == 0x0112)

return callback(view.getUint16(offset + (i * 12) + 8, little));

}

else if ((marker & 0xFF00) != 0xFF00) break;

else offset += view.getUint16(offset, false);

}

return callback(-1);

};

reader.readAsArrayBuffer(file.slice(0, 64 * 1024));

}

// usage:

var input = document.getElementById('input');

input.onchange = function(e) {

getOrientation(input.files[0], function(orientation) {

alert('orientation: ' + orientation);

});

}

1460000007019149?w=512&h=252

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值