新建工程/模块无法加载ets目录下的资源
====================

**问题现象**

新建工程，通过ImageBitmap或其他组件使用src/main/ets目录中的本地图片无法加载。

**可能原因**

若使用DevEco Studio 6.0.0 Beta2及之后的版本创建的新工程，会默认不打包模块src/main目录中的图片资源，具体参考**[copyCodeResource](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/ide-hvigor-build-profile#table1476161719356)**

**解决措施**

1.  将ets目录中的资源文件放置到resources目录中,通过$r的方式引用，参考：
    
    _// 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.");
            })
        }
      }
    }
    
2.  若使用的组件不支持直接使用$r的写法,可以通过resourceManager资源接口获取和使用resources资源目录中的资源，参考：
    
    _// 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%')
      }
    }