# PaletteImageView **Repository Path**: archermind-ti/palette-image-view ## Basic Information - **Project Name**: PaletteImageView - **Description**: 解析图片中主题颜色及相应的匹配背景、标题、正文的推荐颜色。项目从PaletteImageView(https://github.com/DingMouRen/PaletteImageView)移植而来 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 2 - **Created**: 2021-04-30 - **Last Updated**: 2022-06-12 ## Categories & Tags **Categories**: harmonyos-image **Tags**: None ## README # PaletteImageView ### 简介 PaletteImageView是一个可以解析图片中颜色,同时还可以为图片设置多彩阴影的控件。 ### 功能 1. 可以解析图片中的主色调,**默认将主色调作为控件阴影的颜色** 2. 可以**自定义设置控件的阴影颜色** 3. 可以**控制控件四个角的圆角大小**(如果控件设置成正方向,随着圆角半径增大,可以将控件变成圆形) 4. 可以**控制控件的阴影半径大小** 5. 可以分别**控制阴影在x方向和y方向上的偏移量** 6. 可以将图片中的颜色解析出**六种主题颜色**,每一种主题颜色都有相应的**匹配背景、标题、正文的推荐颜色** ### 演示 ![image](screenshot/demo4.gif)![image](screenshot/p3.png) ### 集成 在project的build.gradle中添加mavenCentral()的引用 ```groovy repositories { ... mavenCentral() ... } ``` 在entry的build.gradle中添加依赖 ```groovy dependencies { ... implementation 'com.gitee.archermind-ti:paletteimageview:1.0.2' ... } ``` ### 使用说明 1. xml中直接使用 PaletteImageView ```xml ``` 使用自定义属性,需要引入namespace:`xmlns:app="http://schemas.huawei.com/hap/res-auto"` | xml属性 | 描述 | | -------------------- | ------------------------------------------------------------ | | piv_palette_padding | **表示阴影显示最大空间距离。值为0,没有阴影,大于0,才有阴影。** | | piv_palette_offset_x | 表示阴影在x方向上的偏移量 | | piv_palette_offset_y | 表示阴影在y方向上的偏移量 | | piv_palette_src | 表示图片资源 | | piv_palette_radius | 表示圆角半径 | | piv_shadow_radius | 表示阴影模糊范围 | 2. api 设置 PaletteImageView相关参数 | 方法 | 描述 | | ------------------------------------------------------------ | ------------------------------------------------------------ | | public void setShadowColor(int color) | 表示自定义设置控件阴影的颜色 | | public void setPixelMap(PixelMap pixelMap) | 表示设置控件位图 | | public void setPaletteRadius(int raius) | 表示设置控件圆角半径 | | public void setPaletteShadowOffset(int offsetX, int offsetY) | 表示设置阴影在控件阴影在x方向 或 y方向上的偏移量 | | public void setPaletteShadowRadius(int radius) | 表示设置控件阴影模糊范围 | | public void setOnParseColorListener(OnParseColorListener listener) | 设置控件解析图片颜色的监听器 | | public int[] getVibrantColor() | 表示获取Vibrant主题的颜色数组;假设颜色数组为arry,arry[0]是推荐标题使用的颜色,arry[1]是推荐正文使用的颜色,arry[2]是推荐背景使用的颜色。颜色只是用于推荐,可以自行选择 | | public int[] getDarkVibrantColor() | 表示获取DarkVibrant主题的颜色数组,数组元素含义同上 | | public int[] getLightVibrantColor() | 表示获取LightVibrant主题的颜色数组,数组元素含义同上 | | public int[] getMutedColor() | 表示获取Muted主题的颜色数组,数组元素含义同上 | | public int[] getDarkMutedColor() | 表示获取DarkMuted主题的颜色数组,数组元素含义同上 | | public int[] getLightMutedColor() | 表示获取LightMuted主题的颜色数组,数组元素含义同上 | 3. 解析图片主题色 ```java //设置颜色解析监听 mPaletteImageView.setOnParseColorListener(new OnParseColorListener() { @Override public void onComplete(PaletteImageView paletteImageView) { int[] vibrant = paletteImageView.getVibrantColor(); int[] vibrantDark = paletteImageView.getDarkVibrantColor(); int[] vibrantLight = paletteImageView.getLightVibrantColor(); int[] muted = paletteImageView.getMutedColor(); int[] mutedDark = paletteImageView.getDarkMutedColor(); int[] mutedLight = paletteImageView.getLightMutedColor(); } @Override public void onFail() { } }); ``` ### 编译说明 1. 将项目通过git clone 至本地 2. 使用DevEco Studio 打开该项目,然后等待Gradle 构建完成 3. 点击`Run`运行即可(真机运行可能需要配置签名) ### 版权和许可信息 ``` Copyright (C) 2017 DingMouRen Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License ```