Compare commits

..

2 Commits

Author SHA1 Message Date
yang 28a082737c
Pre Merge pull request !461 from yang/master 2025-02-19 06:46:49 +00:00
yang 115118e238 支持图片携带的EXIF元数据作为显示方向
Signed-off-by: yang <yangweiping7@h-partners.com>
2025-02-19 14:46:37 +08:00
4 changed files with 84 additions and 49 deletions

View File

@ -23,39 +23,66 @@ struct LocalImage {
build() { build() {
Scroll(this.scroller) { Scroll(this.scroller) {
Column() { Column() {
Text("Base Image") Column() {
.fontSize(30) Text($r('app.string.base_image'))
.fontWeight(FontWeight.Bold) .fontSize(20)
Image($rawfile("rotate/rotate.jpg")).width(100).height(100) .fontWeight(FontWeight.Bold)
Row() {
Image($rawfile('rotate/rotate.jpg')).width(100).height(100).margin({ right: 10 })
ImageKnifeComponent({
imageKnifeOption: {
loadSrc: $rawfile('rotate/rotate.jpg'),
objectFit: ImageFit.Contain
}
}).width(100).height(100)
}
}
.margin({ bottom: 20 })
Text($r("app.string.rotate_mirror")) Column() {
.fontSize(30) Text($r('app.string.rotate_mirror'))
.fontWeight(FontWeight.Bold) .fontSize(20)
ImageKnifeComponent({ .fontWeight(FontWeight.Bold)
imageKnifeOption: { Row() {
loadSrc: $rawfile('rotate/rotate_mirror.jpg'), Image($rawfile('rotate/rotate_mirror.jpg')).width(100).height(100).margin({ right: 10 })
objectFit: ImageFit.Contain ImageKnifeComponent({
imageKnifeOption: {
loadSrc: $rawfile('rotate/rotate_mirror.jpg'),
objectFit: ImageFit.Contain
}
}).width(100).height(100)
} }
}).width(100).height(100) }.margin({ bottom: 20 })
Text($r('app.string.rotate_rotate90'))
.fontSize(30)
.fontWeight(FontWeight.Bold)
ImageKnifeComponent({
imageKnifeOption: {
loadSrc: $rawfile('rotate/rotate_rotate90.jpg'),
objectFit: ImageFit.Contain
}
}).width(100).height(100)
Text($r('app.string.rotate_mirror_rotate270'))
.fontSize(30)
.fontWeight(FontWeight.Bold)
ImageKnifeComponent({
imageKnifeOption: {
loadSrc: $rawfile('rotate/rotate_mirror_rotate270.jpg'),
objectFit: ImageFit.Contain
}
}).width(100).height(100)
Column() {
Text($r('app.string.rotate_rotate90'))
.fontSize(20)
.fontWeight(FontWeight.Bold)
Row() {
Image($rawfile('rotate/rotate_rotate90.jpg')).width(100).height(100).margin({ right: 10 })
ImageKnifeComponent({
imageKnifeOption: {
loadSrc: $rawfile('rotate/rotate_rotate90.jpg'),
objectFit: ImageFit.Contain
}
}).width(100).height(100)
}
}.margin({ bottom: 20 })
Column() {
Text($r('app.string.rotate_mirror_rotate270'))
.fontSize(20)
.fontWeight(FontWeight.Bold)
Row() {
Image($rawfile('rotate/rotate_mirror_rotate270.jpg')).width(100).height(100).margin({ right: 10 })
ImageKnifeComponent({
imageKnifeOption: {
loadSrc: $rawfile('rotate/rotate_mirror_rotate270.jpg'),
objectFit: ImageFit.Contain
}
}).width(100).height(100)
}
}
} }
.width('100%') .width('100%')
} }

View File

@ -694,7 +694,7 @@
}, },
{ {
"name": "base_image", "name": "base_image",
"value": "Original Image" "value": "The image don't carry rotation information"
}, },
{ {
"name": "rotate_mirror", "name": "rotate_mirror",

View File

@ -682,7 +682,7 @@
}, },
{ {
"name": "base_image", "name": "base_image",
"value": "原始图片" "value": "图片不携带旋转信息"
}, },
{ {
"name": "test_exif", "name": "test_exif",

View File

@ -196,11 +196,15 @@ export class ImageKnifeLoader {
LogUtil.error('PixelMap setTransferDetached failed:' + JSON.stringify(e)) LogUtil.error('PixelMap setTransferDetached failed:' + JSON.stringify(e))
} }
// 设置翻转和旋转角度 // 设置翻转和旋转角度
if(exif){ if(exif && exif !== 'Top-left'){
let result = ImageKnifeLoader.getOrientation(exif); let result = ImageKnifeLoader.getOrientation(exif);
resPixelmap?.flipSync(result.horizontal, result.vertical); if(result.horizontal || result.vertical) {
resPixelmap?.rotateSync(result.rotate); resPixelmap?.flipSync(result.horizontal, result.vertical);
LogUtil.log('Image set flip , horizontal=' + result.horizontal + ', vertical=' +result.vertical + ', rotate=' + result.rotate); }
if(result.rotate > 0) {
resPixelmap?.rotateSync(result.rotate);
}
LogUtil.log('The normal image set flip , horizontal=' + result.horizontal + ', vertical=' +result.vertical + ', rotate=' + result.rotate);
} }
//获取各个pixelMap的大小 //获取各个pixelMap的大小
@ -275,7 +279,7 @@ export class ImageKnifeLoader {
await imageSource.getImageProperty(image.PropertyKey.ORIENTATION).then((res)=>{ await imageSource.getImageProperty(image.PropertyKey.ORIENTATION).then((res)=>{
exif = res; exif = res;
}).catch((error: BusinessError)=>{ }).catch((error: BusinessError)=>{
LogUtil.info("The normal image don't have rotation information, " + error.message); LogUtil.info("Svg image don't have rotation information, " + error.message);
}) })
await imageSource.createPixelMap(opts) await imageSource.createPixelMap(opts)
@ -286,11 +290,15 @@ export class ImageKnifeLoader {
try { try {
resPixelmap.setTransferDetached(true) resPixelmap.setTransferDetached(true)
// 设置翻转和旋转角度 // 设置翻转和旋转角度
if(exif){ if(exif && exif !== 'Top-left'){
let result = ImageKnifeLoader.getOrientation(exif); let result = ImageKnifeLoader.getOrientation(exif);
resPixelmap?.flipSync(result.horizontal, result.vertical); if(result.horizontal || result.vertical) {
resPixelmap?.rotateSync(result.rotate); resPixelmap?.flipSync(result.horizontal, result.vertical);
LogUtil.log('SvgImage set flip , horizontal=' + result.horizontal + ', vertical=' +result.vertical + ', rotate=' + result.rotate); }
if(result.rotate > 0) {
resPixelmap?.rotateSync(result.rotate);
}
LogUtil.log('Svg image set flip , horizontal=' + result.horizontal + ', vertical=' +result.vertical + ', rotate=' + result.rotate);
} }
} catch (e) { } catch (e) {
LogUtil.error('PixelMap setTransferDetached failed:' + JSON.stringify(e)) LogUtil.error('PixelMap setTransferDetached failed:' + JSON.stringify(e))
@ -527,27 +535,27 @@ export class ImageKnifeLoader {
let vertical: boolean = false; let vertical: boolean = false;
let rotate: number= 0; let rotate: number= 0;
switch (orientation){ switch (orientation){
case "Top-left": break case 'Top-left': break
case "Top-right": case 'Top-right':
horizontal = true; horizontal = true;
break; break;
case "Bottom-left": case 'Bottom-left':
vertical = true; vertical = true;
break break
case "Bottom-right": case 'Bottom-right':
rotate = 180; rotate = 180;
break; break;
case "Left-top": case 'Left-top':
horizontal = true; horizontal = true;
rotate = 270; rotate = 270;
break break
case "Right-top": case 'Right-top':
rotate = 90; rotate = 90;
break; break;
case "Left-bottom": case 'Left-bottom':
rotate = 270; rotate = 270;
break break
case "Right-bottom": case 'Right-bottom':
horizontal = true; horizontal = true;
rotate = 90; rotate = 90;
break; break;