自定义圆形imageview,主要实现圆形图片展示
以下内容由 AI 翻译,如有问题请 点此提交 issue 反馈
简介
circleImageView4cj 是一款图像处理库,能够将图片裁剪为圆形或为其添加边框效果。
功能亮点
- 提供基于中心裁剪的图片缩放模式
- 支持自定义圆形边框样式
项目结构
├─ AppScope
├─ doc # API文档和使用手册存放目录
├─ entry # 示例代码文件夹
├─ circleimageview # circleimageview 库文件夹
│ └─ src
│ └─ main
│ ├─ cangjie
│ │ └─ src
│ │ └─ circle_image_view.cj # 自定义图片裁剪
│ └─ resources
├─ hvigor # 构建工具目录
└─ README.md # circleImageView4cj 介绍及使用说明
Interface Description
For details on main classes and function interfaces, refer to API.
Usage Instructions
-
Import via Module
- Clone or download the project.
- Copy the
circleImageView4cjmodule to your application project directory. - Modify the
oh-package.json5file in your application'sentrydirectory by adding the following under thedependenciesfield:
{ "name": "entry", "version": "1.0.0", "description": "Please describe the basic information.", "main": "", "author": "", "license": "", "dependencies": { "circleimageview": "file:../circleimageview" } }- In the
cjpm.tomlfile located in your application'sentry/src/main/cangjiedirectory, add the following under the[dependencies]section:[dependencies] circleimageview = {path = "../circleimageview", version = "1.0.0"} - Import the
circleimageviewproject in your code:import circleimageview.*
-
Import as a Third-Party Dependency
- Add
circleImageView4cjas a git submodule in your target project:
> cd $PROJECT_ROOT > mkdir third-party > cd third-party > git submodule add "https://gitcode.com/Cangjie-TPC/circleImageView4cj.git"- Modify the
cjpm.tomlfile in your application'sentry/src/main/cangjiedirectory to include the dependency:
[dependencies] circleimageview = {path = "../third-party/circleImageView4cj", version = "1.0.0"}- Use the
circleimageviewcomponent in your project:import circleimageview.*
- Add
Feature Examples
For examples, see entry.
import ohos.base.*
import ohos.component.*
import ohos.state_manage.*
import ohos.state_macro_manage.*
import circleimageview.*
@Entry
@Component
class EntryView {
@State
var data: CircleImageModel = CircleImageModel()
protected override func aboutToAppear() {
this.data = this.data.setImageURI(@r(app.media.hugh)).setDiameter(200.0).setBorderWidth(5.0).setBorderColor(
Color.WHITE).setScaleType(ImageFit.Fill).setDisableCircularTransformation(false)
}
func build() {
Column() {
List(space: 0, initialIndex: 0) {
ListItem() {
Column(5) {
CircleImageView(model: data)
}.align(Alignment.Center).width(200).height(200)
}.height(50.percent).width(100.percent)
ListItem() {
Column(5) {
CircleImageView(model: data)
}.align(Alignment.Center)
}.height(50.percent).backgroundColor(0x000000).width(100.percent)
}.width(100.percent).margin(top: 5)
}
}
}
Constraints and Limitations
Verified on the following versions:
DevEco Studio 5.1.0.828SP1
Cangjie Support Plugin 5.1.0.828
Open Source License
This project is licensed under the Apache License 2.0. Feel free to enjoy and contribute to open source.
How to Contribute
We welcome your Pull Requests, Issue submissions, and any form of contribution.