Forráskód Böngészése

调整播放页圆形封面的大小

onecold 11 hónapja
szülő
commit
6161a80cb6

+ 25 - 0
entry/src/main/ets/common/util/CommUtils.ets

@@ -13,7 +13,32 @@
  * limitations under the License.
  */
 import { CommonConstants2 } from "./CommonConstants2";
+import { image } from "@kit.ImageKit";
+import { fileIo } from "@kit.CoreFileKit";
 
+export function imagePathToPixelMap(imagePath: string): Promise<image.PixelMap> {
+  return new Promise((resolve, reject) => {
+    try {
+      let file = fileIo.openSync(imagePath, fileIo.OpenMode.READ_ONLY | fileIo.OpenMode.CREATE)
+      let fd = file.fd;
+
+      let imageSource = image.createImageSource(fd);
+      let opts: image.DecodingOptions = { editable: false };
+
+      // 使用ImageSource创建PixelMap
+      imageSource.createPixelMap(opts).then(pixelMap => {
+        resolve(pixelMap);
+      }).catch((error:Error) => {
+        console.error(`onecold 创建PixelMap失败: ${error.message}`);
+        reject(error);
+      });
+
+    } catch (error) {
+      console.error(`处理异常: ${error.message}`);
+      reject(error);
+    }
+  });
+}
 
 export function secondToTime(seconds: number): string {
   let hourUnit = CommonConstants2.HOUR_UNIT * CommonConstants2.HOUR_UNIT;

+ 2 - 1
entry/src/main/ets/controller/AvSessionController.ets

@@ -24,6 +24,7 @@ import { image } from '@kit.ImageKit';
 import { SettingPage } from '../pages/SettingPage';
 import { Utility } from '../common/util/Utility';
 import LyricUtil from '../common/util/LyricUtil';
+import { imagePathToPixelMap } from '../common/util/CommUtils';
 
 const TAG = 'onecold AvSessionController';
 
@@ -141,7 +142,7 @@ export class AvSessionController {
         if(pixelMapPath.startsWith('http')){
           imagePixMap =pixelMapPath
         }else{
-          imagePixMap = await ImageUtil.imagePathToPixelMap(pixelMapPath)
+          imagePixMap = await imagePathToPixelMap(pixelMapPath)
         }
       }else{
         imagePixMap = await ImageUtil.getPixelMapFromMedia($r('app.media.ic_avatar2'));

+ 7 - 7
entry/src/main/ets/view/LocalMusic.ets

@@ -17,6 +17,7 @@ import {
   StrUtil,
   ToastUtil
 } from '@pura/harmony-utils';
+import { imagePathToPixelMap } from '../common/util/CommUtils';
 import { unifiedDataChannel, uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
 import { CommonConstants } from '../common/constants/CommonConstants';
 import Logger from '../common/util/Logger';
@@ -7356,7 +7357,7 @@ export struct LocalMusic {
 
   @State imageLabel: PixelMap | Resource = CommonConstants.musicBgList[0];
   @State imageLabelBg: PixelMap | Resource = CommonConstants.musicBgList[0];
-  @State rotateAngle2: number = 0
+  @State rotateAngle2: number = -9
   @StorageLink('imageColor') imageColor: string = 'rgba(0, 0, 2, 1.00)';
   @State cover: string | undefined = '';
   @State artist: string | undefined = ''
@@ -7826,7 +7827,7 @@ export struct LocalMusic {
     if (cover === undefined) {
       return;
     }
-    ImageUtil.imagePathToPixelMap(cover).then((value) => {
+    imagePathToPixelMap(cover).then((value) => {
       let headFilter = effectKit.createEffect(value);
       if (headFilter !== null) {
         headFilter.blur(15);
@@ -7888,7 +7889,7 @@ export struct LocalMusic {
         iterations: 1,
         curve: Curve.Linear
       }, () => {
-        this.rotateAngle2 = 0
+        this.rotateAngle2 = -9
       })
     }
 
@@ -7921,7 +7922,7 @@ export struct LocalMusic {
         curve: Curve.Linear,
         iterations: 1,
       }, () => {
-        this.rotateAngle2 = -40;
+        this.rotateAngle2 = -45;
       });
     }
 
@@ -8433,7 +8434,6 @@ export struct LocalMusic {
       .onClick(async () => {
         this.setLoopMode()
 
-
       })
 
 
@@ -8566,7 +8566,7 @@ export struct LocalMusic {
         Image($r('app.media.ic_music_disc'))
           .width(245)
           .height(245)
-          .margin({ right: 20, left: 20 })
+          .margin({ right: 20, left: 20 ,top:this.isCoverRectangle||this.isLandscape?0:43})
           .aspectRatio(1)
           .opacity(this.isCoverOpacity() || this.isCoverRectangle ? 0 : 1)
           .visibility(this.isCoverOpacity() || this.isCoverRectangle ? Visibility.None : Visibility.Visible)
@@ -8619,7 +8619,7 @@ export struct LocalMusic {
                 (this.isCoverOpacity() ? (px2vp(this.windowHeight)*0.62) : this.isCoverRectangle ? 320 : 162))
               .objectFit(this.isCoverRectangle ? ImageFit.Contain : ImageFit.Auto)
               .alt(this.imageLabel)
-              .margin({ right: 20, left: 20 })
+              .margin({ right: 20, left: 20,top:this.isCoverRectangle||this.isLandscape?0:43 })
               .aspectRatio(1)
               .opacity(this.opacityValueImage)
               .scale({ x: this.scaleValueImage, y: this.scaleValueImage }) // 添加缩放效果