目录

Comparison Between Motion Blur and Static Blur

Overview

Blurring is a popular technique in image processing that helps draw attention to the main subject by softening the finer details and making the focal point more pronounced. As shown in the following figure, blurring not only adds depth to the UI but also helps organize elements by their importance. When combined with motion, it creates motion blur effects. These effects are widely used in scenarios like page transitions and image scaling, where the goal is to highlight content or guide the user's focus.

Since the blur algorithm requires detailed pixel-level processing, real-time rendering for the component demands that the blurring process be completed within an extremely short cycle. This is especially challenging when components are also handling animation tasks, as it can strain computing resources and lead to issues like lagging and frame dropping.

As applications become more widespread, optimizing the performance of blurring has become crucial. Given that the system offers both static and motion blur capabilities, this document compares their performance in the context of "transitions combined with image blurring." You are advised to use static blur in scenarios where the background and content do not need real-time updates, as this can reduce lagging and frame dropping and improve user experience.

When to Use

The difference between static blur and motion blur lies in whether the content being blurred is static or motion. For example, blurring a video is dynamic, while blurring an image is static.

Example Scenarios

The following describes the performance comparison and analysis of motion blur and static blur in the transition with blurred image scenario (full-screen modal transition to a modal page with a blurred images). Note that because motion blur and static blur rely on different underlying algorithms, setting the same blur radius value does not produce equivalent visual effects. To compare their performance differences more accurately based on visual consistency, the blur radius values for both motion and static blur scenarios are adjusted to achieve as similar a visual effect as possible. In this example, setting the motion blur radius to 13 and the static blur radius to 3 yields closely comparable image blur effects, serving as the equivalent condition for visual consistency.

The following is an example in which motion blur is used to blur an image. You can directly set the Image component blur to add the blur effect to the image.

import { window } from '@kit.ArkUI';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';

@Component
export struct MotionBlur {
  @Consume('navPathStack') navPathStack: NavPathStack;
  @State isShowMotionBlur: boolean = false;
  @State bottomSafeHeight: number = 0;

  aboutToAppear(): void {
    window.getLastWindow(this.getUIContext().getHostContext()!, (err, windowBar) => {
      if (err.code) {
        return;
      }

      try {
        this.bottomSafeHeight =
          this.getUIContext()
            .px2vp(windowBar.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height);
      } catch (error) {
        let err: BusinessError = error as BusinessError;
        hilog.warn(0x000, 'testTag', `getWindowAvoidArea failed, code=${err.code}, message=${err.message}`);
      }
      windowBar.setWindowLayoutFullScreen(true)
        .catch((err: BusinessError) => {
          hilog.error(0x000, 'testTag', `setWindowLayoutFullScreen failed, code=${err.code}, message=${err.message}`);
        })

    });
  }

  @Builder
  motionBlurBuilder() {
    Stack({ alignContent: Alignment.Bottom }) {
      Image($r('app.media.test'))
        .width('100%')
        .height('100%')
        .objectFit(ImageFit.Fill)
        .blur(13)
      Button('close')
        .width('90%')
        .height(40)
        .margin({ bottom: this.bottomSafeHeight + 16 })
        .onClick(() => {
          this.isShowMotionBlur = false;
        })
    }
    .width('100%')
    .height('100%')
  }

  build() {
    NavDestination() {
      Column() {
        Button('motion blur')
          .width('90%')
          .height(40)
          .onClick(() => {
            this.isShowMotionBlur = true;
          })
          .bindContentCover(this.isShowMotionBlur, this.motionBlurBuilder(), {
            modalTransition: ModalTransition.DEFAULT
          })
      }
      .padding({ bottom: this.bottomSafeHeight + 16 })
      .width('100%')
      .height('100%')
      .justifyContent(FlexAlign.End)
    }
    .hideTitleBar(true)
  }
}

Figure 1 Motion blur

The following is an example in which motion blur is used to blur an image. The procedure is as follows:

  1. Call createPixelMap to create the PixelMap of an image.

  2. Call createEffect to create a Filter instance.

  3. Use blur in the Filter class to add the blur effect to the image.

    import { image } from '@kit.ImageKit';
    import { effectKit } from '@kit.ArkGraphics2D';
    import { window } from '@kit.ArkUI';
    import { hilog } from '@kit.PerformanceAnalysisKit';
    import { BusinessError } from '@kit.BasicServicesKit';
    
    @Component
    export struct StaticBlur {
      @Consume('navPathStack') navPathStack: NavPathStack;
      @State isShowStaticBlur: boolean = false;
      @State pixelMap: image.PixelMap | undefined = undefined;
      @State imgSource: image.ImageSource | undefined = undefined;
      @State bottomSafeHeight: number = 0;
    
      aboutToAppear(): void {
        window.getLastWindow(this.getUIContext().getHostContext()!, (err, windowBar) => {
          if (err.code) {
            return;
          }
          try {
            this.bottomSafeHeight =
              this.getUIContext()
                .px2vp(windowBar.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height);
          } catch (error) {
            let err: BusinessError = error as BusinessError;
            hilog.warn(0x000, 'testTag', `getWindowAvoidArea failed, code=${err.code}, message=${err.message}`);
          }
          windowBar.setWindowLayoutFullScreen(true)
            .catch((err: BusinessError) => {
              hilog.error(0x000, 'testTag', `setWindowLayoutFullScreen failed, code=${err.code}, message=${err.message}`);
            })
        });
      }
    
      aboutToDisappear(): void {
        this.pixelMap?.release();
        this.pixelMap = undefined;
        this.imgSource?.release();
        this.imgSource = undefined;
      }
    
      async staticBlur(): Promise<void> {
        let context: Context = this.getUIContext().getHostContext()!;
        await context.resourceManager.getRawFileContent('test.png')
          .then((fileData: Uint8Array) => {
            let buffer: ArrayBuffer = fileData.buffer.slice(0);
            this.imgSource = image.createImageSource(buffer);
          })
          .catch((err: BusinessError) => {
            hilog.error(0x000, 'testTag', `getRawFileContent failed, code=${err.code}, message=${err.message}`);
          })
        let opts: image.InitializationOptions = {
          editable: true,
          pixelFormat: 3,
          size: {
            height: 4,
            width: 6
          }
        };
        await this.imgSource!.createPixelMap(opts).then((pixelMap: image.PixelMap) => {
          const blurRadius: number = 3;
          let headFilter: effectKit.Filter = effectKit.createEffect(pixelMap);
          if (headFilter !== null) {
            headFilter.blur(blurRadius);
            headFilter.getEffectPixelMap().then((pixelMap: image.PixelMap) => {
              this.pixelMap = pixelMap;
              this.imgSource?.release();
            });
          }
        })
      }
    
      @Builder
      staticBlurBuilder() {
        Stack({ alignContent: Alignment.Bottom }) {
          Image(this.pixelMap)
            .width('100%')
            .height('100%')
            .objectFit(ImageFit.Fill)
          Button('close')
            .width('90%')
            .height(40)
            .margin({ bottom: this.bottomSafeHeight + 16 })
            .onClick(() => {
              this.isShowStaticBlur = false;
              this.pixelMap?.release();
            })
        }
        .width('100%')
        .height('100%')
      }
      
      build() {
        NavDestination() {
          Column() {
            Button('static blur')
              .width('90%')
              .height(40)
              .onClick(() => {
                this.isShowStaticBlur = true;
                this.staticBlur();
              })
              .bindContentCover(this.isShowStaticBlur, this.staticBlurBuilder(), {
                modalTransition: ModalTransition.DEFAULT
              })
          }
          .padding({ bottom: this.bottomSafeHeight + 16 })
          .width('100%')
          .height('100%')
          .justifyContent(FlexAlign.End)
        }
        .hideTitleBar(true)
      }
    }

Figure 2 Static blur

Effect Comparison

The following describes how to use the frame rate analyzer in the built-in Profiler of DevEco Studio to capture trace data during the button-triggered transition process to analyze the performance metrics between motion and static blur scenarios. Because transitions are triggered by button clicks, the start of a transition can be located precisely at the end of the Click tag under User Events. The end of a transition corresponds to the point where consecutive RenderFrame (GPU draw execution) tags cease to occur continuously.

As shown in the preceding figure, the RenderFrame tag shows that the average rendering time of the motion blur transition is 6.113 ms. On the Present Fence tag (image display signal), the average frame rate of motion blur transition is 108.0 fps.

As shown in the preceding figure, the RenderFrame tag shows that the average rendering time of the static blur transition is 3.357 ms. The Present Fence tag shows that the average frame rate of static blur transition is 119.9 fps. Compared to motion blur, static blur reduces average rendering time by approximately 45% (Note: Performance metrics vary based on application scenarios, device models, and system versions; refer to actual test data).

In summary, under visually equivalent conditions, static blur significantly outperforms motion blur. This is due to the difference of the bottom-layer implementation mechanism. Static blur only needs to complete one-time blur processing and does not need real-time rendering. Motion blur requires continuous blur calculation for each frame. Although a smoother and more coherent visual transition effect can be created in an ideal case, rendering complexity and resource consumption are significantly increased. If the page is too complex, frame freezing or frame loss may occur.

Sample Code