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

View File

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

View File

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

View File

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