From 54acd6ddef9d44c9f2d7415bd7a049706706f3d5 Mon Sep 17 00:00:00 2001 From: CodingGorit Date: Tue, 29 Jul 2025 20:00:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E5=87=86=E5=87=BA=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/ImageGenerate.ets | 11 +++++------ entry/src/main/resources/base/element/string.json | 4 ++++ entry/src/main/resources/en_US/element/string.json | 4 ++++ entry/src/main/resources/zh_CN/element/string.json | 4 ++++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/entry/src/main/ets/pages/ImageGenerate.ets b/entry/src/main/ets/pages/ImageGenerate.ets index af18736..1d3d95e 100644 --- a/entry/src/main/ets/pages/ImageGenerate.ets +++ b/entry/src/main/ets/pages/ImageGenerate.ets @@ -27,8 +27,6 @@ import { import NavigationParam from "../model/NavigationParam"; import modelPredict from "../utils/Predict"; import Logger from '../utils/Logger'; -import { gaussianRun } from "../utils/Gaussion"; - @Observed class BackgroundImageItem { @@ -214,7 +212,7 @@ export struct ImageGenerate { Logger.info('inputs length is ' + inputs.length); // predict modelPredict(modelBuffer.buffer.slice(0), inputs).then(async outputs => { - Logger.info("==== MS_LITE_LOG: MS_LITE predict success ===="); + Logger.info('==== MS_LITE_LOG: MS_LITE predict success ===='); let output: Float32Array = new Float32Array(outputs[0].getData()); @@ -293,14 +291,14 @@ export struct ImageGenerate { imageSourceBg.release(); }) } catch (error) { - Logger.error("Failed to get media content", JSON.stringify(error)); + Logger.error('Failed to get media content', JSON.stringify(error)); } }) // 5. close fileIo fileIo.closeSync(file); imageSource.release(); } catch (err) { - Logger.error("MS_LITE_LOG: uri: open file fd failed." + err); + Logger.error('MS_LITE_LOG: uri: open file fd failed.' + err); } } @@ -348,7 +346,7 @@ export struct ImageGenerate { .onClick(() => { if (!this.canMergeImage) { this.getUIContext().getPromptAction().showToast({ - message: "图像合成中!请勿切换背景", + message: $r("app.string.generate_tips"), alignment: Alignment.Center, }) return; @@ -358,6 +356,7 @@ export struct ImageGenerate { this.currentPreviewImageIndex = index; this.handleMergeImage(); this.previewImageList.forEach((item, idx) => { + Logger.info(`PreviewImage => ${JSON.stringify(item)}, idx => ${idx}`); if (idx !== index) { this.previewImageList[idx].selected = false; } diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index d825eaf..19980c2 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -36,6 +36,10 @@ "name":"segment_btn_text_second", "value": "generate" }, + { + "name": "generate_tips", + "value": "Image compositing! Do not switch backgrounds" + }, { "name": "preview_img_list_001", "value": "default" diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json index 6ac9428..36f11e7 100644 --- a/entry/src/main/resources/en_US/element/string.json +++ b/entry/src/main/resources/en_US/element/string.json @@ -36,6 +36,10 @@ "name":"segment_btn_text_second", "value": "generate" }, + { + "name": "generate_tips", + "value": "Image compositing! Do not switch backgrounds" + }, { "name": "preview_img_list_001", "value": "default" diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json index 77e2265..d4b05aa 100644 --- a/entry/src/main/resources/zh_CN/element/string.json +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -36,6 +36,10 @@ "name":"segment_btn_text_second", "value": "合成" }, + { + "name": "generate_tips", + "value": "图像合成中!请勿切换背景" + }, { "name": "preview_img_list_001", "value": "默认" -- Gitee From d729d006e9ad027c6877a79747707dbdd2b597c5 Mon Sep 17 00:00:00 2001 From: CodingGorit Date: Wed, 30 Jul 2025 15:54:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix=EF=BC=9A=E5=8F=8C=E5=BC=95=E5=8F=B7?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E4=B8=BA=E5=8D=95=E5=BC=95=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constants/ImageDataListConstant.ets | 20 ++--- entry/src/main/ets/pages/ImageGenerate.ets | 84 +++++++++---------- entry/src/main/ets/pages/Index.ets | 32 +++---- entry/src/main/ets/utils/Gaussion.ets | 4 +- entry/src/main/ets/utils/Predict.ets | 8 +- 5 files changed, 74 insertions(+), 74 deletions(-) diff --git a/entry/src/main/ets/common/constants/ImageDataListConstant.ets b/entry/src/main/ets/common/constants/ImageDataListConstant.ets index b723c4a..bda46c2 100644 --- a/entry/src/main/ets/common/constants/ImageDataListConstant.ets +++ b/entry/src/main/ets/common/constants/ImageDataListConstant.ets @@ -19,7 +19,7 @@ export const MODEL_INPUT_HEIGHT = 1024; export const MODEL_INPUT_WIDTH = 1024; export const BLACKGROUND_THEADHOLD = 0.88; -export const MODEL_NAME = "rmbg_fp16.ms"; +export const MODEL_NAME = 'rmbg_fp16.ms'; /** * List data constants for all features @@ -29,14 +29,14 @@ export class ListDataConstants { * Service directory list */ static readonly IMG_LIST: Resource[] = [ - $r("app.media.img_001"), - $r("app.media.img_002"), - $r("app.media.img_003"), - $r("app.media.img_004"), - $r("app.media.img_005"), - $r("app.media.img_006"), - $r("app.media.img_007"), - $r("app.media.img_008"), - $r("app.media.img_009"), + $r('app.media.img_001'), + $r('app.media.img_002'), + $r('app.media.img_003'), + $r('app.media.img_004'), + $r('app.media.img_005'), + $r('app.media.img_006'), + $r('app.media.img_007'), + $r('app.media.img_008'), + $r('app.media.img_009'), ] } diff --git a/entry/src/main/ets/pages/ImageGenerate.ets b/entry/src/main/ets/pages/ImageGenerate.ets index 1d3d95e..1e92470 100644 --- a/entry/src/main/ets/pages/ImageGenerate.ets +++ b/entry/src/main/ets/pages/ImageGenerate.ets @@ -13,19 +13,19 @@ * limitations under the License. */ -import { image } from "@kit.ImageKit"; -import { resourceManager } from "@kit.LocalizationKit"; -import { fileIo } from "@kit.CoreFileKit"; -import { ItemRestriction, SegmentButton, SegmentButtonOptions, SegmentButtonTextItem } from "@kit.ArkUI"; +import { image } from '@kit.ImageKit'; +import { resourceManager } from '@kit.LocalizationKit'; +import { fileIo } from '@kit.CoreFileKit'; +import { ItemRestriction, SegmentButton, SegmentButtonOptions, SegmentButtonTextItem } from '@kit.ArkUI'; import { BLACKGROUND_THEADHOLD, ListDataConstants, MODEL_INPUT_HEIGHT, MODEL_INPUT_WIDTH, MODEL_NAME -} from "../common/constants/ImageDataListConstant"; -import NavigationParam from "../model/NavigationParam"; -import modelPredict from "../utils/Predict"; +} from '../common/constants/ImageDataListConstant'; +import NavigationParam from '../model/NavigationParam'; +import modelPredict from '../utils/Predict'; import Logger from '../utils/Logger'; @Observed @@ -56,13 +56,13 @@ export struct PreviewImage { Column() { } .height(34) - .width("100%") - .id("id_swiper_image_gradient") + .width('100%') + .id('id_swiper_image_gradient') .alignRules({ - top: { anchor: "__container__", align: VerticalAlign.Top }, - left: { anchor: "__container__", align: HorizontalAlign.Start }, - right: { anchor: "__container__", align: HorizontalAlign.End }, - bottom: { anchor: "__container__", align: VerticalAlign.Bottom } + top: { anchor: '__container__', align: VerticalAlign.Top }, + left: { anchor: '__container__', align: HorizontalAlign.Start }, + right: { anchor: '__container__', align: HorizontalAlign.End }, + bottom: { anchor: '__container__', align: VerticalAlign.Bottom } }) .margin({ top: 34 }) .linearGradient({ @@ -81,13 +81,13 @@ export struct PreviewImage { .height(16) .fontSize(12) .lineHeight(16) - .id("id_swiper_image_type") - .fontColor("#FFF") + .id('id_swiper_image_type') + .fontColor('#FFF') .alignRules({ - top: { anchor: "id_swiper_image_gradient", align: VerticalAlign.Top }, - left: { anchor: "id_swiper_image_gradient", align: HorizontalAlign.Start }, - right: { anchor: "id_swiper_image_gradient", align: HorizontalAlign.End }, - bottom: { anchor: "id_swiper_image_gradient", align: VerticalAlign.Bottom } + top: { anchor: 'id_swiper_image_gradient', align: VerticalAlign.Top }, + left: { anchor: 'id_swiper_image_gradient', align: HorizontalAlign.Start }, + right: { anchor: 'id_swiper_image_gradient', align: HorizontalAlign.End }, + bottom: { anchor: 'id_swiper_image_gradient', align: VerticalAlign.Bottom } }) .margin({ top: 10, @@ -105,7 +105,7 @@ export struct PreviewImage { .border({ width: this.imgItem.selected ? 1 : 0, radius: 8, - color: this.imgItem.selected ? "#0A59F7" : Color.Transparent + color: this.imgItem.selected ? '#0A59F7' : Color.Transparent }) } } @@ -116,8 +116,8 @@ export struct ImageGenerate { pathStack: NavPathStack = new NavPathStack(); private modelName: string = MODEL_NAME; @State tabOptions: SegmentButtonOptions = SegmentButtonOptions.tab({ - buttons: [{ text: $r("app.string.segment_btn_text_first") }, - { text: $r("app.string.segment_btn_text_second") }] as ItemRestriction, + buttons: [{ text: $r('app.string.segment_btn_text_first') }, + { text: $r('app.string.segment_btn_text_second') }] as ItemRestriction, fontColor: 'rgba(0,0,0,0.9)', selectedFontColor: 'rgba(0,0,0,0.6)', fontSize: 14, @@ -136,15 +136,15 @@ export struct ImageGenerate { @State tabSelectedIndexes: number[] = [this.currentTab]; @State currentPreviewImageIndex: number = 0; @State previewImageList: BackgroundImageItem[] = [ - new BackgroundImageItem($r("app.media.img_001"), $r("app.string.preview_img_list_001"), true), - new BackgroundImageItem($r("app.media.img_002"), $r("app.string.preview_img_list_002"), false), - new BackgroundImageItem($r("app.media.img_003"), $r("app.string.preview_img_list_003"), false), - new BackgroundImageItem($r("app.media.img_004"), $r("app.string.preview_img_list_004"), false), - new BackgroundImageItem($r("app.media.img_005"), $r("app.string.preview_img_list_005"), false), - new BackgroundImageItem($r("app.media.img_006"), $r("app.string.preview_img_list_006"), false), - new BackgroundImageItem($r("app.media.img_007"), $r("app.string.preview_img_list_007"), false), - new BackgroundImageItem($r("app.media.img_008"), $r("app.string.preview_img_list_008"), false), - new BackgroundImageItem($r("app.media.img_009"), $r("app.string.preview_img_list_009"), false) + new BackgroundImageItem($r('app.media.img_001'), $r('app.string.preview_img_list_001'), true), + new BackgroundImageItem($r('app.media.img_002'), $r('app.string.preview_img_list_002'), false), + new BackgroundImageItem($r('app.media.img_003'), $r('app.string.preview_img_list_003'), false), + new BackgroundImageItem($r('app.media.img_004'), $r('app.string.preview_img_list_004'), false), + new BackgroundImageItem($r('app.media.img_005'), $r('app.string.preview_img_list_005'), false), + new BackgroundImageItem($r('app.media.img_006'), $r('app.string.preview_img_list_006'), false), + new BackgroundImageItem($r('app.media.img_007'), $r('app.string.preview_img_list_007'), false), + new BackgroundImageItem($r('app.media.img_008'), $r('app.string.preview_img_list_008'), false), + new BackgroundImageItem($r('app.media.img_009'), $r('app.string.preview_img_list_009'), false) ]; @State photoUri: string = ''; handleSegmentButtonChange: Callback = (index: number) => { @@ -321,10 +321,10 @@ export struct ImageGenerate { RelativeContainer() { // Original Image Placeholder Image(this.currentTab === 0 ? this.photoUri : this.outMergePixMap) - .id("id_display_img") + .id('id_display_img') .alignRules({ - middle: { anchor: "__container__", align: HorizontalAlign.Center }, - center: { anchor: "__container__", align: VerticalAlign.Center } + middle: { anchor: '__container__', align: HorizontalAlign.Center }, + center: { anchor: '__container__', align: VerticalAlign.Center } }) .padding({ top: 24, @@ -334,9 +334,9 @@ export struct ImageGenerate { }) .objectFit(ImageFit.Contain) } - .width("100%") + .width('100%') .height(480) - .backgroundColor($r("app.color.image_display_are_background")) + .backgroundColor($r('app.color.image_display_are_background')) if (this.currentTab === 1) { Row() { @@ -346,7 +346,7 @@ export struct ImageGenerate { .onClick(() => { if (!this.canMergeImage) { this.getUIContext().getPromptAction().showToast({ - message: $r("app.string.generate_tips"), + message: $r('app.string.generate_tips'), alignment: Alignment.Center, }) return; @@ -370,14 +370,14 @@ export struct ImageGenerate { .scrollBar(BarState.Off) .edgeEffect(EdgeEffect.Spring) .friction(0.8) - }.width("100%") + }.width('100%') // List End } - }.width("100%").height("100%").margin({ top: 8 }) + }.width('100%').height('100%').margin({ top: 8 }) } - .title({ builder: this.navigationTitle($r("app.string.image_page_navbar_title")), height: 56 }) - .backgroundColor($r("app.color.window_background")) + .title({ builder: this.navigationTitle($r('app.string.image_page_navbar_title')), height: 56 }) + .backgroundColor($r('app.color.window_background')) .onReady((context: NavDestinationContext) => { this.pathStack = context.pathStack; const ret = this.pathStack.getParamByIndex(0) as NavigationParam; @@ -388,7 +388,7 @@ export struct ImageGenerate { @Builder navigationTitle(content: ResourceStr) { Text(content) - .fontColor("rgba(0,0,0,0.9)") + .fontColor('rgba(0,0,0,0.9)') .fontSize(20) .fontWeight(FontWeight.Bold) .lineHeight(27) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index c193e38..e44cf1f 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -26,24 +26,24 @@ struct Index { build() { Navigation(this.pathStack) { RelativeContainer() { - Text($r("app.string.home_text_generate_tips")) - .id("id_home_tips") + Text($r('app.string.home_text_generate_tips')) + .id('id_home_tips') .alignRules({ - middle: { anchor: "__container__", align: HorizontalAlign.Center}, - bottom: { anchor: "id_home_btn", align: VerticalAlign.Top } + middle: { anchor: '__container__', align: HorizontalAlign.Center}, + bottom: { anchor: 'id_home_btn', align: VerticalAlign.Top } }) .fontWeight(400) .fontSize(12) .lineHeight(16) - .fontColor("rgba(0,0,0,0.6)") + .fontColor('rgba(0,0,0,0.6)') .margin({ bottom: 24}) - Button($r("app.string.home_btn_text")) - .id("id_home_btn") + Button($r('app.string.home_btn_text')) + .id('id_home_btn') .alignRules({ - left: { anchor: "__container__", align: HorizontalAlign.Start}, - right: { anchor: "__container__", align: HorizontalAlign.End}, - bottom: { anchor: "__container__", align: VerticalAlign.Bottom}, + left: { anchor: '__container__', align: HorizontalAlign.Start}, + right: { anchor: '__container__', align: HorizontalAlign.End}, + bottom: { anchor: '__container__', align: VerticalAlign.Bottom}, }) .margin({ bottom: 16, left: 16, right: 16}) .onClick(() => { @@ -69,23 +69,23 @@ struct Index { }); }) } - .id("id_home_navigation") - .height("100%") - .width("100%") + .id('id_home_navigation') + .height('100%') + .width('100%') } .title({ builder: this.titleBuilder, height: 112}) .mode(NavigationMode.Stack) - .backgroundColor($r("app.color.window_background")) + .backgroundColor($r('app.color.window_background')) } @Builder titleBuilder() { Column() { - Text($r("app.string.home_navbar_title")) + Text($r('app.string.home_navbar_title')) .fontSize(30) .fontWeight(FontWeight.Bold) .lineHeight(40) - .fontColor("rgba(0,0,0,0.9)") + .fontColor('rgba(0,0,0,0.9)') .margin({ left: 16, right: 16, diff --git a/entry/src/main/ets/utils/Gaussion.ets b/entry/src/main/ets/utils/Gaussion.ets index ac48126..c3c2d2c 100644 --- a/entry/src/main/ets/utils/Gaussion.ets +++ b/entry/src/main/ets/utils/Gaussion.ets @@ -17,7 +17,7 @@ import { MODEL_INPUT_HEIGHT } from '../common/constants/ImageDataListConstant'; import Logger from './Logger'; function gaussianRun(mat: Uint8Array) { - Logger.info("----- gaussian run -----"); + Logger.info('----- gaussian run -----'); let rMat = new Array>(); let gMat = new Array>(); let bMat = new Array>(); @@ -50,7 +50,7 @@ function gaussianRun(mat: Uint8Array) { } function calcGaussian(calcMat: Array>) { - Logger.info("_...-----calcGaussian run----------") + Logger.info('_...-----calcGaussian run----------') for (let i = 1; i < calcMat.length - 1; ++i) { for (let j = 1; j < calcMat[i].length - 1; ++j) { calcMat[i][j] = getOpValue(calcMat, i, j) diff --git a/entry/src/main/ets/utils/Predict.ets b/entry/src/main/ets/utils/Predict.ets index 5f0c457..070eccb 100644 --- a/entry/src/main/ets/utils/Predict.ets +++ b/entry/src/main/ets/utils/Predict.ets @@ -25,13 +25,13 @@ export default async function modelPredict context.cpu.threadNum = 2; context.cpu.threadAffinityMode = 1; context.cpu.precisionMode = 'enforce_fp32'; - Logger.info("MS_LITE_LOG load model before ...") + Logger.info('MS_LITE_LOG load model before ...') // 2. Load Model let msLiteModel: mindSporeLite.Model = await mindSporeLite.loadModelFromBuffer(modelBuffer, context); - Logger.info("MS_LITE_LOG load model after...") + Logger.info('MS_LITE_LOG load model after...') // 3. Set input data let modelInputs: mindSporeLite.MSTensor[] = msLiteModel.getInputs(); - Logger.info("MS_LITE_L06 msLiteModel.getInputs ...") + Logger.info('MS_LITE_L06 msLiteModel.getInputs ...') // This model does not support resizing other shapes. for (let i = 0; i < inputsBuffer.length; i++) { let inputBuffer = inputsBuffer[i]; @@ -42,6 +42,6 @@ export default async function modelPredict // 4. Execute reasoning Logger.info('=========MS_LITE_L06: MS_LITE predict start====='); let modelOutputs: mindSporeLite.MSTensor[] = await msLiteModel.predict(modelInputs) ; - Logger.info("MS_LITE_LOG predict after ..."); + Logger.info('MS_LITE_LOG predict after ...'); return modelOutputs; } \ No newline at end of file -- Gitee