问题模块 |
---|
API和组件 |
同一台手机,用[小程序示例]上传A图片正常,我们自己小程序、其他开发者的一个小程序上传A相片时颠倒
第一张是[小程序示例],第二张是我们自己小程序,第三张是一款其他开发者的已上线的共享相册小程序
ps.1.不是所有手机都会颠倒(目前测试感觉是IOS会颠倒、安卓不会) 2.不是所有的相片都会颠倒
网友回复
手动实现了一下反转
// /utils/util.js
const concatArrayBuffer = (... arrays ) => {
let totalLength = 0 ;
for ( let arr of arrays ) {
totalLength += arr . length ;
}
let result = new Uint8ClampedArray ( totalLength );
let offset = 0 ;
for ( let arr of arrays ) {
result . set ( arr , offset );
offset += arr . length ;
}
return result ;
}
const revertImage = ( data , width , height ) => {
if (! data ) return data ;
let dataViews = [];
let len = width * 4 ;
for ( let i = 0 ; i < height ; i ++) {
let start = i * width * 4 ;
let newBuff = data . slice ( start , start + len );
dataViews . unshift ( newBuff );
}
let result = concatArrayBuffer (... dataViews );
return result . buffer ;
}
module . exports = {
revertImage
}
// /pages/XXXPage.js
wx . canvasGetImageData ({
canvasId: 'myCanvas' ,
x: 0 ,
y: 0 ,
width: width ,
height: height ,
success ( res ) {
wx . hideLoading ();
// 3. IOS图像反转
let buffer = res . data . buffer ;
try {
let systemInfo = wx . getSystemInfoSync ();
let platform = systemInfo . platform ;
if ( platform === 'ios' ) {
buffer = util . revertImage ( res . data , res . width , res . height );
}
} catch ( e ) {
}
......
知道问题在哪了,示例用的wx.previewImage,我们因为要对图片进行处理不能用wx.previewImage,用的image ,同时用了wx.getImageInfo ,但wx.getImageInfo没返相片exif中的Orientation 方向
会解决这个问题么?谢谢@黄思程
调用接口的代码能否发一下看看