diff --git a/ArkUI/entry/src/main/ets/pages/GetResourceManager.ets b/ArkUI/entry/src/main/ets/pages/GetResourceManager.ets new file mode 100644 index 0000000000000000000000000000000000000000..0409a18d56bf99f9b8c5a3512273819110e27e7c --- /dev/null +++ b/ArkUI/entry/src/main/ets/pages/GetResourceManager.ets @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:新建工程/模块无法加载ets目录下的资源 +*/ + +// [Start GetResourceManager] +// xxx.ets +@Entry +@Component +struct ImageExample { + private settings: RenderingContextSettings = new RenderingContextSettings(true); + private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings); + // Replace "common/images/example.jpg" with the image resource file you use. + // private img: ImageBitmap = new ImageBitmap("common/images/example.jpg"); // This relative path writing will make it impossible to record pictures in the new template + private img: ImageBitmap = new ImageBitmap(this.getUIContext().getHostContext()?.resourceManager + .getDrawableDescriptorByName("example") + .getPixelMap()); // You can refer to the interface for using resourceManager + + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Canvas(this.context) + .width('100%') + .height('100%') + .backgroundColor('#ffff00') + .onReady(() => { + this.context.drawImage(this.img, 0, 0, 500, 500, 0, 0, 400, 200) + this.img.close() + }) + } + .width('100%') + .height('100%') + } +} +// [End GetResourceManager] diff --git a/ArkUI/entry/src/main/ets/pages/GetResources.ets b/ArkUI/entry/src/main/ets/pages/GetResources.ets new file mode 100644 index 0000000000000000000000000000000000000000..869ea8b5d7878f43328ca18f551a182ac6e861f2 --- /dev/null +++ b/ArkUI/entry/src/main/ets/pages/GetResources.ets @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:新建工程/模块无法加载ets目录下的资源 +*/ + +// [Start GetResource] +// xxx.ets +@Entry +@Component +struct VideoPlayer { + private controller: VideoController = new VideoController() + private previewUris: Resource = $r('app.media.preview') + private innerResource: Resource = $rawfile('videoTest.mp4') + + build() { + Column() { + Video({ + src: this.innerResource, + previewUri: this.previewUris, + controller: this.controller + }) + .onUpdate((event) => { // Triggered when the playback progress changes. + console.info("Video update."); + }) + .onPrepared((event) => { // Triggered when video preparation is complete. + console.info("Video prepared."); + }) + .onError(() => { // Triggered when the video playback fails. + console.error("Video error."); + }) + .onStop(() => { // Triggered when the video playback stops. + console.info("Video stopped."); + }) + } + } +} +// [End GetResource]