google-slides-api - Google Slides API,可以使用十六进制设置颜色吗?
问题描述
是否可以使用十六进制格式设置元素形状背景颜色,例如 #B6D7A8 ?我在这里看到一个例子, 谷歌幻灯片 API-如何更改某种颜色的所有形状的文本颜色
但是,Google Slide API 参考并没有提到它。我想确定,并且专门针对 Java 环境。
https://developers.google.com/slides/reference/rest/v1/presentations.pages/other#Page.OpaqueColor
requests.add(new Request()
.setUpdateShapeProperties(new UpdateShapePropertiesRequest()
.setObjectId(elementRandomString)
.setShapeProperties(new ShapeProperties()
.setShapeBackgroundFill(new ShapeBackgroundFill()
.setSolidFill(new SolidFill()
.setColor(new Col)
解决方案
Google Slides API-How to change text color for all shapes of a specific color 中提供的答案使用Apps Script 中的Slide Service来设置颜色。
要回答您的问题,无法以 HEX 格式设置颜色。如您提供的参考文档中所述,您需要在 OpaqueColor 中提供一个RgbColor对象。
解决方法:
- 将您的十六进制颜色转换为
RGB
然后除以值,red
以获得RgbColorblue
接受的值,即green
255
0.0 ~ 1.0
您可能想将此视为参考:java : convert Hex color #RRGGBB to rgb rgb?
- 根据您转换的,和值设置RgbColor 。
red
blue
green
示例代码:
requests.add(new Request()
.setUpdateShapeProperties(new UpdateShapePropertiesRequest()
.setObjectId(elementRandomString)
.setShapeProperties(new ShapeProperties()
.setShapeBackgroundFill(new ShapeBackgroundFill()
.setSolidFill(new SolidFill()
.setColor(new Color()
.setRgbColor(new RgbColor()
.setRed(redFloatValue)
.setBlue(blueFloatValue)
.setGreen(greenFloatValue))))))));
参考:
推荐阅读
- html - 如何合并页眉、页脚和主体
- php - PHP变量在不同文件中的使用
- python - Python PyQt5 QGraphicsView 抓轮事件
- matlab - CMake 使用 MCC 将 Matlab .m 文件编译为 .exe
- linux - 如何在本地机器上为节点服务器打开 80 端口?
- python - Python 包含非空主体的抽象方法是否违反了预期的虚拟/抽象设计模式?
- python-3.x - 如何将 linux 终端命令发送到 python 后台进程 $test.py &
- c# - EF6 表拆分和异常“ReferentialConstraint 中的依赖属性映射到存储生成的列。列:'Id'。”
- google-bigquery - 在 BigQuery 中转置输出
- java - 如何使用 rxjava 进行异步改造调用。我必须异步拨打 100 多个电话