本文介绍了如何设置组合颜色为两种不同颜色物体的重叠区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了两个不同颜色不同的自定义视图。据我的应用程序功能的用户会拖动屏幕,当拖动对象将互相重叠的那些对象。我想分化重叠区域,如何设置为重叠区的颜色相结合。看看下面的图片。在这里,我使用的画布,创建这些自定义视图两个圆是两个不同的看法。

I am creating different custom views with two different colors. According to my app features user will drag those objects on the screen, when dragging objects will overlap each other. I want to differentiated the overlapped area, how to set the combined color for overlapped Area.Look at the below image. Here I am using canvas for creating those custom views two circles are two different views.

编辑:如果我用不透明度128,我能看到的背景颜色,但我想重叠的物体颜色的组合色

If I use opacity 128 I am able to see the background color, but I want the combination color of overlapped objects colors.

推荐答案

混色你正在寻找有时也被称为直观的颜色混合或颜色系统:

The Color mixing you are looking for is sometimes called Intuitive Color Mixing, or the RYB Color System:

RYB

CC授权

从上直观的颜色混合算法,这个本文由Nathan戈西特和陈宝权概括了直观的彩色系统作品:

A quote from this paper by Nathan Gossett and Baoquan Chen on algorithms for intuitive color mixing summarizes how the intuitive color system works:

在这种模式下,红色,黄色和蓝色作为纯粹的原色。红色和黄色的搭配,形成橙色,黄色和蓝色混合,形成绿色和蓝色和红色的搭配,形成紫[...]。这些颜色未受过训练的观察者会期望获得使用儿童漆[...]。此外,许多人不认为白色的所有颜色的混合,而是因为没有颜色的(一张空白的画布)。更常见的假设是多种颜色混合在一起会产生一个泥泞的黑褐色的颜色。

RYB没有在Android的混合模式来实现,并不能真正混合的α/不同的混合模式进行模拟。

RYB is not implemented in Android's blend modes and can't really be simulated by mixing alpha/different blend modes.

大多数的计算机图形应用程序使用的 RGB CMYK 色彩空间:

Most computer graphics applications make use of the RGB or CMYK color spaces:

CMYK

CMY是基于减色。减色混合意味着,从白色,为我们增添色彩,其结果变暗。 CMYK用于在用于打印在例如图像混合颜色Photoshop和Illustrator。

CMY is based on subtractive color. Subtractive color mixing means that, starting with white, as we add color, the result gets darker. CMYK is used for mixing colors in images intended for printing in e.g. Photoshop and Illustrator.

RGB

RGB的基础上加色。在计算机屏幕上的颜色与光用加色法创建的。加色混合始于黑,随着越来越多的颜色会添加,结果变得更亮,结束于白色。

RGB is based on Additive Color. The colors on a computer screen are created with light using the additive color method. Additive color mixing begins with black and as more color is added, the result gets lighter and ends in white.

网站更详细地讨论CMYK和RGB。

This site discusses CMYK and RGB in more detail.

在没有RGB也不是CMYK不会混合蓝色和黄色产生绿色,否则一般来说,直观的颜色混合。为了实现在Android上RYB色系统是相当复杂。由Nathan戈西特和陈宝权该报援引上述建议与在纸张的最后实现C中的算法解决方案。该算法可以在Android上一个自定义的混合来实现。 <一href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.2_r1.1/android/graphics/drawable/Drawable.java#Drawable.setColorFilter%28int,android.graphics.PorterDuff.Mode%29"><$c$c>Drawable.setColorFilter()使用<一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.2_r1.1/android/graphics/PorterDuffColorFilter.java#PorterDuffColorFilter"><$c$c>PorterDuffColorfilter延伸<一href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.2_r1.1/android/graphics/ColorFilter.java#ColorFilter"><$c$c>ColorFilter.子类<一href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.0_r1/android/graphics/ColorFilter.java"><$c$c>ColorFilter如这个,以便问题都必须在本地$ C $完成c。使用NDK。

In neither RGB nor CMYK does mixing blue and yellow produce green, or generally speaking, intuitive color mixes. To implement a RYB color system on Android would be quite involved. The paper by Nathan Gossett and Baoquan Chen quoted above proposes a solution with an algorithm implemented in C at the very end of the paper. This algorithm could be implemented in a custom blend on Android. Drawable.setColorFilter() uses PorterDuffColorfilter which extends ColorFilter. Subclassing ColorFilter as discussed in this SO question would have to be done in native code using the NDK.

CMYK颜色混合解决方法

如果您有兴趣使用CMYK颜色混合作为一种解决办法,我已经包括了如何能在下面做了基本的例子。在这个例子中,青色颜色的圆圈和黄色圆圈将被混合以产生一个绿色交集。

In case you are interested in using a CMYK color mixing as a workaround, I've included a basic example of how it can be done below. In this example, A cyan-color circle and a yellow-color circle will be blended to produce a green intersection.

在Adobe Illustrator中创建这些的PNG图片文件开始:

Starting with these .png image files created in Adobe Illustrator:

使用十六进制颜色值0x00ffff(青色)和0xffff00(黄色)。

with hex color value 0x00ffff (cyan) and 0xffff00 (yellow).

添加到您的绘制文件夹的名称cyancircle.png和yellowcircle.png。

Add them to your drawable folder with names cyancircle.png and yellowcircle.png.

配置您的main.xml中的布局如下:

Configure your main.xml layout as follows:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#ffffff"
    android:padding="30dp">

<ImageView
    android:id="@+id/bluecircle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/cyancircle">
</ImageView>

<ImageView
    android:id="@+id/yellowcircle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/yellowcircle"
    android:layout_marginTop="30dp">
</ImageView>
</RelativeLayout>

创建活动:

import android.app.Activity;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.widget.ImageView;

public class PorterDuffTestActivity extends Activity {
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ImageView yellowCircle = (ImageView)findViewById(R.id.yellowcircle);

        yellowCircle.getDrawable().setColorFilter(0x88ffff00, PorterDuff.Mode.MULTIPLY);
    }
}

输出:

的限制这种方法是,顶部的形状的阿尔法必须被设置为50%(即88,在0x88ffff00)。对于黄这个工程合理的很好,但其他颜色的alpha效果可能是不能接受(颜色可能似乎是另一种颜色,如红色变为粉红色与白色背景上的低阿尔法值)。混合模式最终是可以接受的,你要看组颜色你要使用,并会采取一些试验。还要注意的背景颜色可能会影响在混合模式的圆圈'的颜色。在本实施例的背景设置为白色。

The limitation to this method is that the top shape's alpha has to be set to 50% (the "88" in "0x88ffff00"). For yellow this works reasonable well but for other colors the alpha effect may not be acceptable (the color may appear to be another color, e.g. red becomes pink with low alpha values on white background). Which blend mode is ultimately acceptable for you depends on the set of colors you are going to use and will take some experimentation. Also note the background color may affect the circles' colors in blend mode. In this example the background is set to white.

这篇关于如何设置组合颜色为两种不同颜色物体的重叠区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 23:45