Compare commits

..

2 Commits

Author SHA1 Message Date
yang 1d165c951d
Pre Merge pull request !461 from yang/master 2025-02-19 02:34:03 +00:00
yang 7e28f28f8f 支持图片携带的EXIF元数据作为显示方向
Signed-off-by: yang <yangweiping7@h-partners.com>
2025-02-19 10:32:55 +08:00
4 changed files with 49 additions and 84 deletions

View File

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

View File

@ -694,7 +694,7 @@
}, },
{ {
"name": "base_image", "name": "base_image",
"value": "The image don't carry rotation information" "value": "Original Image"
}, },
{ {
"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,15 +196,11 @@ export class ImageKnifeLoader {
LogUtil.error('PixelMap setTransferDetached failed:' + JSON.stringify(e)) LogUtil.error('PixelMap setTransferDetached failed:' + JSON.stringify(e))
} }
// 设置翻转和旋转角度 // 设置翻转和旋转角度
if(exif && exif !== 'Top-left'){ if(exif){
let result = ImageKnifeLoader.getOrientation(exif); let result = ImageKnifeLoader.getOrientation(exif);
if(result.horizontal || result.vertical) {
resPixelmap?.flipSync(result.horizontal, result.vertical); resPixelmap?.flipSync(result.horizontal, result.vertical);
}
if(result.rotate > 0) {
resPixelmap?.rotateSync(result.rotate); resPixelmap?.rotateSync(result.rotate);
} LogUtil.log('Image set flip , horizontal=' + result.horizontal + ', vertical=' +result.vertical + ', rotate=' + result.rotate);
LogUtil.log('The normal image set flip , horizontal=' + result.horizontal + ', vertical=' +result.vertical + ', rotate=' + result.rotate);
} }
//获取各个pixelMap的大小 //获取各个pixelMap的大小
@ -279,7 +275,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("Svg image don't have rotation information, " + error.message); LogUtil.info("The normal image don't have rotation information, " + error.message);
}) })
await imageSource.createPixelMap(opts) await imageSource.createPixelMap(opts)
@ -290,15 +286,11 @@ export class ImageKnifeLoader {
try { try {
resPixelmap.setTransferDetached(true) resPixelmap.setTransferDetached(true)
// 设置翻转和旋转角度 // 设置翻转和旋转角度
if(exif && exif !== 'Top-left'){ if(exif){
let result = ImageKnifeLoader.getOrientation(exif); let result = ImageKnifeLoader.getOrientation(exif);
if(result.horizontal || result.vertical) {
resPixelmap?.flipSync(result.horizontal, result.vertical); resPixelmap?.flipSync(result.horizontal, result.vertical);
}
if(result.rotate > 0) {
resPixelmap?.rotateSync(result.rotate); resPixelmap?.rotateSync(result.rotate);
} LogUtil.log('SvgImage set flip , horizontal=' + result.horizontal + ', vertical=' +result.vertical + ', rotate=' + 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))
@ -535,27 +527,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;