android - 如何根据背景颜色更改浮动绘图的色调?
问题描述
我有一个 Android 应用程序,用户可以在其中(取消)选择图像。图像显示在 ViewPager 中,嵌套在 FrameLayout 中。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
.. ViewPager stuff ..
<CheckBox
android:id="@+id/selectImageCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginEnd="16dp"
android:layout_marginBottom="32dp"
android:alpha="0.9"
android:button="@drawable/ic_checkbox_36dp"
android:textColor="@color/colorLightGray" />
</FrameLayout>
复选框位于右下角。我的问题是我想根据复选框后面的背景更改 Checkbox drawable 的色调。如果是深色图像,则白色色调效果很好。如果图像非常明亮,或者可能根本不够宽,无法到达复选框,那么白色就不起作用,灰色会更好。
我正在努力寻找一种方法来确定放置复选框的矩形中的可见颜色。(我知道如何以编程方式更改色调)。或者有没有更优雅的解决方案来根据周围的颜色改变可绘制的色调?
解决方案
首先检查图像的尺寸并确定它是否到达复选框。
如果不是,那么灰色。
如果是这样,则可以拍摄图像下半部分的大部分并确定其整体像素亮度。
使用该值,可以确定哪种颜色最能在图像中脱颖而出。
推荐阅读
- c# - Mononame 不生成 Debug.xnb
- javascript - 指针在链表中是如何工作的?
- delphi - Delphi IDE 冻结代码完成并跳转到声明
- nestjs - NestJs/TypeORM:如何保存多对多
- swift - Typescript 联合类型的 Swift 等价物是什么?
- java - Java 构造问题 findmissing 元素
- arrays - Javascript将一个数组中的元素推入另一个数组
- css - tablerow 背景颜色不适用于 tabledata #css
- swift - 如何从自定义上滑菜单中显示控制器
- python - 将 csv 数据转换为逗号的单独列表