OpenHarmony 视图缩放组件—subsampling-scale-image-view

简介

深度缩放视图,图像显示,手势平移缩放双击等

效果图(旋转、缩放、平移)

下载安装

ohpm install @ohos/subsampling-scale-image-view 

使用说明

生成SubsamplingScaleImageView

import {SubsamplingScaleImageView} from '@ohos/subsampling-scale-image-view';
...
//创建model对象
@State model: SubsamplingScaleImageView.Model  = new SubsamplingScaleImageView.Model()
...
build() {
  Stack({ alignContent: Alignment.Bottom }) {
   //使用SubsamplingScaleImageView组件
   SubsamplingScaleImageView({ model: this.model })
   Column({ space: 5 }) {
     Swiper(this.swiperController) {
       Row({ space: 5 }) {
         Text('This image is 7,800 x 6,240 pixels. On most devices it will be subsampled, and higher quality tiles are loaded as you zoom in.')
           .width('100%')
           .height(60)
           .layoutWeight(1)
           .fontColor(0xffffff)
           .textAlign(TextAlign.Center)
           .fontSize(16)
         Image($r('app.media.next'))
           .width(30)
           .height(30)
           .margin({ top: 6, left: 10 })
           .onClick((event: ClickEvent) => {
             this.index = 1;

           })
       }.width('100%').height(60).backgroundColor(0x3d3d3d)

       Row({ space: 5 }) {
         Image($r('app.media.previous')).width(30).height(30).margin({ top: 6 }).onClick((event: ClickEvent) => {
           this.index = 0;
         })
         Text('This image has been rotated 90 degrees. Tap the button to rotate it. EXIF rotation is supported for external files.')
           .width('100%')
           .height(60)
           .layoutWeight(1)
           .fontColor(0xffffff)
           .textAlign(TextAlign.Center)
           .fontSize(16)
         Image($r('app.media.rotate'))
           .width(30)
           .height(30)
           .margin({ top: 6, left: 10, right: 20 })
           .onClick((event: ClickEvent) => {
             this.mRotate += 90;
             this.model.setOrientation(this.mRotate)
           })
       }.width('100%').height(60).backgroundColor(0x3d3d3d)

     }
     .index(this.index)
     .autoPlay(false)
     .indicator(false) // 默认开启指示点
     .loop(false) // 默认开启循环播放
     .duration(50)
     .vertical(false) // 默认横向切换
     .itemSpace(0)
     .onChange((index: number) => {
       if (index == 1) {
         
         this.model.setImage($r('app.media.swissroad'));
       }
     })
   }.height(60).backgroundColor(0x3d3d3d).align(Alignment.Bottom)
 }
}
//设置图片源
aboutToAppear() {
 this.model.setImage($r('app.media.card'));
}
...

接口说明

  1. 设置图片资源
public setImage(src: string | PixelMap | Resource)
public setImage(src: string | PixelMap | Resource, previewSource: string | Resource)
public setImage(src: string | PixelMap | Resource, state: ImageViewState)
  1. 设置图片是否可缩放
setZoomEnabled(zoomEnabled: boolean)
  1. 设置图片是否可平移
public setPanEnabled(panEnabled: boolean)
  1. 设置图片最大缩放比
public setMaxScale(maxScale: number)
  1. 设置图片旋转角度
public setOrientation(degrees: number)
  1. 获取图片高宽
public getSWidth()  
public getSHeight()
  1. 单击监听器
public setSingleTapListener(listener: OnSingleTapListener)
  1. 长按监听器
public setLongPressListener(listener: OnLongPressListener)
  1. 双击监听器
public setDoubleTapListener(listener: OnDoubleTapListener)

约束与限制

在下述版本验证通过:

  • DevEco Studio 版本: 4.1 Canary(4.1.3.317)
  • OpenHarmony SDK:API11 (4.1.0.36)

目录结构

|---- subsampling-scale-image-view 
    |---- entry # 示例代码文件夹      
    |---- library  
    |     |---- src
    |          |---- main
    |                |---- ets          
    |                      |---- components  # 库文件夹               
    |                           |---- SubsamplingScaleImageView.ets  # 自定义组件
    |                           |---- ImageViewState.ets  # 组件状态数据封装类  
    |     |---- index.ets  # 对外接口              
    |     |---- README.md  # 安装使用方法
阅读全文
下载说明:
1、本站所有资源均从互联网上收集整理而来,仅供学习交流之用,因此不包含技术服务请大家谅解!
2、本站不提供任何实质性的付费和支付资源,所有需要积分下载的资源均为网站运营赞助费用或者线下劳务费用!
3、本站所有资源仅用于学习及研究使用,您必须在下载后的24小时内删除所下载资源,切勿用于商业用途,否则由此引发的法律纠纷及连带责任本站和发布者概不承担!
4、本站站内提供的所有可下载资源,本站保证未做任何负面改动(不包含修复bug和完善功能等正面优化或二次开发),但本站不保证资源的准确性、安全性和完整性,用户下载后自行斟酌,我们以交流学习为目的,并不是所有的源码都100%无错或无bug!如有链接无法下载、失效或广告,请联系客服处理!
5、本站资源除标明原创外均来自网络整理,版权归原作者或本站特约原创作者所有,如侵犯到您的合法权益,请立即告知本站,本站将及时予与删除并致以最深的歉意!
6、如果您也有好的资源或教程,您可以投稿发布,成功分享后有站币奖励和额外收入!
7、如果您喜欢该资源,请支持官方正版资源,以得到更好的正版服务!
8、请您认真阅读上述内容,注册本站用户或下载本站资源即您同意上述内容!
原文链接:https://www.1024c.cn/archives/21326,转载请注明出处。
0

评论0

显示验证码
没有账号?注册  忘记密码?