1.调色板HSSFPlalette

/*** workbook调色板* 调色板的第一个颜色索引从0x8开始,第二个索引是0x9...一直到0x40, */
public final class HSSFPalette {/*** 可编辑的调色板,调色板的颜色可以自定义,当调色板颜色没有填充满时用黑色填充* 可编辑的调色板定义了56种颜色,索引值范围:[0x8, 0x]*/private PaletteRecord _palette;protected HSSFPalette(PaletteRecord palette){_palette = palette;}/*** 获取给定索引的颜色** @param index 调色面板中颜色索引,索引从0x8开始,在0x8到0x40之间:[8,64]* @return 返回颜色,如果索引未填充,则返回null*/public HSSFColor getColor(short index) {// 处理特例:默认黑色if (index == HSSFColorPredefined.AUTOMATIC.getIndex()) {return HSSFColorPredefined.AUTOMATIC.getColor();}// 从自定义byte[] b = _palette.getColor(index);return (b == null) ? null : new CustomColor(index, b);}/*** 获取给定索引的颜色** @param index 调色面板中颜色索引,在0x8到0x40之间:[8,64]* @return 返回颜色,如果索引未填充,则返回null*/public HSSFColor getColor(int index) {return getColor((short)index);}/*** 查找给定颜色的第一次出现,即查找给定颜色是否在调色板中存在** @param red RGB颜色红色分量:[0, 255]* @param green RGB颜色绿色分量:[0, 255]* @param blue RGB颜色蓝色分量:[0, 255]* @return 返回颜色,如果此调色板中不存在此颜色,返回null*/public HSSFColor findColor(byte red, byte green, byte blue){byte[] b = _palette.getColor(PaletteRecord.FIRST_COLOR_INDEX);for (short i = PaletteRecord.FIRST_COLOR_INDEX; b != null;b = _palette.getColor(++i)){if (b[0] == red && b[1] == green && b[2] == blue){return new CustomColor(i, b);}}return null;}/*** 在自定义调色板中找到最接近的匹配颜色。 找到颜色之间的距离的方法是相当重要的。* @param red   匹配的颜色的红色分量。* @param green 匹配的颜色的绿色分量。* @param blue  匹配的颜色的蓝色分量。* @return 返回最接近的颜色,如果没有当前的自定义颜色,则返回null*/public HSSFColor findSimilarColor(byte red, byte green, byte blue) {return findSimilarColor(unsignedInt(red), unsignedInt(green), unsignedInt(blue));}/*** 在自定义调色板中找到最接近的匹配颜色。 找到颜色之间的距离的方法是相当重要的** @param red   匹配的颜色的红色分量。* @param green 匹配的颜色的绿色分量。* @param blue  匹配的颜色的蓝色分量。* @return 返回最接近的颜色,如果没有当前的自定义颜色,则返回null*/public HSSFColor findSimilarColor(int red, int green, int blue) {HSSFColor result = null;int minColorDistance = Integer.MAX_VALUE;byte[] b = _palette.getColor(PaletteRecord.FIRST_COLOR_INDEX);for (short i = PaletteRecord.FIRST_COLOR_INDEX; b != null;b = _palette.getColor(++i)){int colorDistance = Math.abs(red - unsignedInt(b[0])) +Math.abs(green - unsignedInt(b[1])) +Math.abs(blue - unsignedInt(b[2]));if (colorDistance < minColorDistance){minColorDistance = colorDistance;result = getColor(i);}}return result;}/*** Turn a byte of between -127 and 127 into something between*  0 and 255, so distance calculations work as expected.*/private int unsignedInt(byte b) {return 0xFF & b;}/*** 设置调色板中索引index处的颜色** @param index 调色板的索引* @param red RGB红色分量* @param green RGB绿色分量* @param blue RGB蓝色分量*/public void setColorAtIndex(short index, byte red, byte green, byte blue) {_palette.setColor(index, red, green, blue);}/*** 将一个新的颜色添加到一个空的颜色插槽* @param red       The red component* @param green     The green component* @param blue      The blue component** @return  返回新的颜色** @throws RuntimeException if there are more more free color indexes.*/public HSSFColor addColor( byte red, byte green, byte blue ){byte[] b = _palette.getColor(PaletteRecord.FIRST_COLOR_INDEX);short i;for (i = PaletteRecord.FIRST_COLOR_INDEX; i < PaletteRecord.STANDARD_PALETTE_SIZE + PaletteRecord.FIRST_COLOR_INDEX; b = _palette.getColor(++i)){if (b == null){setColorAtIndex( i, red, green, blue );return getColor(i);}}throw new RuntimeException("Could not find free color index");}/*** 内部类:自定义颜色类*/private static final class CustomColor extends HSSFColor {// 当前颜色的索引值private short _byteOffset;private byte _red;private byte _green;private byte _blue;/*** @param byteOffset */public CustomColor(short byteOffset, byte[] colors){this(byteOffset, colors[0], colors[1], colors[2]);}private CustomColor(short byteOffset, byte red, byte green, byte blue){_byteOffset = byteOffset;_red = red;_green = green;_blue = blue;}@Overridepublic short getIndex(){return _byteOffset;}@Overridepublic short[] getTriplet(){return new short[]{(short) (_red   & 0xff),(short) (_green & 0xff),(short) (_blue  & 0xff)};}@Overridepublic String getHexString(){StringBuffer sb = new StringBuffer();sb.append(getGnumericPart(_red));sb.append(':');sb.append(getGnumericPart(_green));sb.append(':');sb.append(getGnumericPart(_blue));return sb.toString();}private String getGnumericPart(byte color){String s;if (color == 0){s = "0";}else{int c = color & 0xff; //as unsignedc = (c << 8) | c; //pad to 16-bits = Integer.toHexString(c).toUpperCase(Locale.ROOT);while (s.length() < 4){s = "0" + s;}}return s;}}
}

2.获取调色板方式

public class TestHSSFPalette {public static void main(String[] args) {HSSFWorkbook workbook = new HSSFWorkbook();// 获取workbook的调色板HSSFPalette hssfPalette = workbook.getCustomPalette();// 获取调色板中索引为8的HSSFColorHSSFColor hssfColor = hssfPalette.getColor((short)8);System.out.println(hssfColor.getHexString());HSSFColor hssfColor2 = hssfPalette.getColor((short)0x30);System.out.println(hssfColor2.getHexString());}
}

XLS调色面板HSSFPalette相关推荐

  1. Java图像处理--------RGB调色面板

    Java图像处理--------RGB调色面板 一:概述 因为我们知道颜色是由R.G.B.三种颜色所组成的,那么我们只需要更改这三个的数值.我们就可以实现一个简单的调色面板:以下是代码演示: 二:代码 ...

  2. unity使用ugui自制调色面板

    突然想实现一个调色面板,然后开工... 首先找找有没有什么接口可调,木有找到,找到一些调用win32实现的本地颜色面板的调用,感觉不科学,反正多平台肯定是搞不定的. 既然没找到,还是老老实实的自己写吧 ...

  3. java创建内部面板类_java-RGB调色面板的实现(事件监听器之匿名内部类)

    题目要求: **要求写一个案例,使用三个JSlider分别选取R.G.B三原色的值,用户可以通过活动JSlider的滑块来动态的合成一种颜色,合成的颜色显示在界面上.** 代码思路解析: 1.所需要的 ...

  4. java 颜色板_java-RGB调色面板的实现(事件监听器之匿名内部类)

    题目要求: **要求写一个案例,使用三个JSlider分别选取R.G.B三原色的值,用户可以通过活动JSlider的滑块来动态的合成一种颜色,合成的颜色显示在界面上.** 代码思路解析: 1.所需要的 ...

  5. POI 颜色Color

    1. 颜色概述 颜色Color是单元格的基本样式,单元格默认颜色为黑色 - 单元格边框颜色 - 单元格填充色 - 单元格字体颜色 2. 预定自颜色 POI中预定义了56种颜色,索引从0x8 - 0x4 ...

  6. 使用photoshop2021对有阴影的背光摄影照片进行调色修改

    小清新与写真摄影中,校园风一直是一个比较火的题材.首先因为大多写真拍摄以年轻女性为主,其中不乏学生,而摄影师也有很多是大学生,所以校园风对于这部分人来说是比较好的题材,既能轻松获得熟悉的校园场景,又能 ...

  7. 新手必备pr 2021快速入门教程「十」PR基础视频调色

    PR2021快速入门教程,学完之后,制作抖音视频,vlog,电影混剪,日常记录等不在话下!零基础,欢迎入坑! 本节内容 调色是视频后期制作流程中必不可少的重要环节.每当我们看电影的时候,就会感觉电影里 ...

  8. 【平面设计基础】12:ACR调色

    第12节:ACR调色 OVERVIEW 第12节:ACR调色 一.调色思路 二.调色面板 三.调色实例 1.照片分析 2.照片调色: (1)白平衡矫正: (2)整体调节: (3)还原照片细节: (4) ...

  9. 达芬奇调色技术:调色快速入门基础

    达芬奇作为一款视频后期工具,今天来主要分享达芬奇调色面板快速入门的教程. 第一步:首先拖入视频素材,Alt+s迅速创建4个节点.四个节点分别命名为调整影调.还原色彩.风格化.整体调整. 第二步:若是使 ...

最新文章

  1. ASP.NET Session 使用报告(转贴)
  2. 接受拒绝算法_通过算法拒绝大学学位
  3. 容器(container)技术之发展简史
  4. 第五章节 类的继承(访问修饰符)
  5. 《Effective Python 2nd》——推导与生成
  6. 自适应的设置字体的方式
  7. 网络调试助手无法连接tcp服务器,W5500 TCP 客户端网络调试助手连不上
  8. deepin安装过程
  9. MP3参数,格式,术语有关一切内容详解。
  10. gee微端服务器系统设置,Gee引擎微端服务器
  11. 如何定向网件路由防火墙与URL
  12. Android reckon 控制项目打包版本
  13. Halcon之Variation Model
  14. C语言中的取绝对值函数
  15. 智能测试实践之路-UI缺陷检测
  16. Oracle数据库:sql语言结构,数据查询语言DQL,select * from table;算术,别名,连接,去重等操作
  17. cent7 安装 notepadqq
  18. Unity3D基本知识 构造函数 this用法
  19. MSP430初学:MSP430单片机C语言基础(二)
  20. electron-v8.2.1-win32-x64.zip 下载失败(npm install electron 安装失败)

热门文章

  1. Vue全家桶:Vuex
  2. 电脑双核CPU具体是什么意思?
  3. 微信小程序毕业设计 基于微信药店药品商城小程序开题报告
  4. OpenCV 学习笔记03 凸包convexHull、道格拉斯-普克算法Douglas-Peucker algorithm、approxPloyDP 函数...
  5. 开源中国(OSChina)源码解析(1)——源码导入
  6. windows系统搭建portal服务器,Windows下安装部署OpenPortal1.1
  7. bach cello
  8. Missive是什么软件?协作式电子邮件Missive有什么特点
  9. photoshop图像处理技术(二)
  10. 贝壳 OLAP 平台架构及演进