LargeImage:基于 OpenHarmony 的大图加载与交互组件项目

用户可借助此项目在OpenHarmony应用中实现大图加载、缩放、拖动查看等交互功能。核心功能包括图像加载、缩放控制、平移查看、旋转设置及事件监听,支持设置最大缩放比例,满足大图浏览需求。【此简介由AI生成】

Branch1Tags7
# LargeImage

Introduction

LargeImage is a tool that provides zooming, scrolling, and panning for image viewing.

You can use it to:

  1. Load an image.
  2. Scale an image.
  3. Pan to view a large image.

How to Install

ohpm install @ohos/largeimage

How to Use

import { LargeImage } from '@ohos/largeimage'; // Import the code.

@Entry
@ComponentV2
struct Index {
  @Provider() model: LargeImage.Model = new LargeImage.Model(); // Create a model.
  @Local index: number = 0;
  @Local rotateValue: number = 0;

  aboutToAppear() {
    this.model.setImage($r('app.media.tiger')); // Set the image source.
    this.model.setMaxScale(2); // Set the maximum zoom scale.
  }

  build() {
    Stack({ alignContent: Alignment.Bottom }) {
      LargeImage() // Load the large image.
      Image($r('app.media.rotate'))
        .width(30)
        .height(30)
        .margin({ top: 6 ,left:10,right:20})
        .onClick((event: ClickEvent) => {
          this.rotateValue +=90;
          this.model.setOrientation(this.rotateValue) // Set the image orientation.
        })
    }
  }
}

Available APIs

API Parameter Return Value Description
setImage src: Resource void Sets image source.
setZoomEnabled zoomEnabled: boolean void Sets whether to enable zooming for the image.
setPanEnabled panEnabled: boolean void Sets whether to enable panning for the image.
setMaxScale maxScale: number void Sets the maximum zoom scale of the image.
setOrientation degrees: number void Sets the image orientation.
getLoadedImageWidth
getLoadedImageHeight
N/A number Obtains the width and height of the source image.
setSingleTapListener listener: OnSingleTapListener void Sets a listener for single tap events.
setLongPressListener listener: OnLongPressListener void Sets a listener for long-press events.
setDoubleTapListener listener: OnDoubleTapListener void Sets a listener for double-tap events.

Constraints

This project has been verified in the following versions:

  • DevEco Studio NEXT Developer Beta3: 5.0 (5.0.3.530), SDK: API 12 (5.0.0.35(SP3))

Directory Structure

|---- LargeImage
|     |---- entry     # Sample code
|     |---- library     # LargeImage library
|               |---- LargeImage.ets     # External APIs
|     |---- README.md # Readme   

About obfuscation

  • Code obfuscation, please seeCode Obfuscation
  • If you want the LargeImage library not to be obfuscated during code obfuscation, you need to add corresponding exclusion rules in the obfuscation rule configuration file obfuscation-rules.txt:
-keep
./oh_modules/@ohos/largeimage

How to Contribute

If you find any problem when using this project, submit an issue or a PR.

License

This project is licensed under Apache License 2.0.

Introduction

用户可借助此项目在OpenHarmony应用中实现大图加载、缩放、拖动查看等交互功能。核心功能包括图像加载、缩放控制、平移查看、旋转设置及事件监听,支持设置最大缩放比例,满足大图浏览需求。【此简介由AI生成】

Customize your domain