在具有某些指定发型图像图案的发型上应用滤色器的最佳方法是什么?

What is the best way to apply color filter on hair style with some specified hair style image pattern?(在具有某些指定发型图像图案的发型上应用滤色器的最佳方法是什么?)

本文介绍了在具有某些指定发型图像图案的发型上应用滤色器的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为发型沙龙开发一个安卓应用程序.我有两张图片.一种是发型(头发),另一种是发色图案.我可以根据特定的 rgb 值更改发型的颜色.

I am developing an android application for hair style salon.I am having two images. One is hairstyle (hair) and another is hair color pattern. I am able to change the color of hair style based on specific rgb value.

我的代码如下:

int color = Color.rgb(182,132, 84); // getting rgb value 
Paint paint = new Paint();
paint.setColorFilter(new LightingColorFilter(color, 1));

transform.reset();
transform.postTranslate(-width / 2.0f, -height / 2.0f);
transform.postRotate(getDegreesFromRadians(angle));
transform.postScale(scale, scale);
transform.postTranslate(position.getX(), position.getY());

canvas.drawBitmap(bitmap, transform, paint); 

但是我正在寻找的解决方案是假设我有彩色图案图像,那么它不可能从渐变图像中获取 rgb 值.

But what the solution i am searching that suppose i have color pattern image then its not possible to get rgb value from gradient image.

喜欢:

我想在头发图像上应用上述图案.如果有人有想法请回复.

I want to apply the above pattern on hair image. If anyone have idea please reply.

推荐答案

只是为了好玩和好奇,我尝试自己实现你的想法.
准备好以下两个 xxhdpi 图像(480 dpi,为了使它们能够很好地缩放 - 然后我将它们放在 /res/drawable-xxhdpi 文件夹中)

Just for fun, and curiosity, I tried to make my own implementation of your idea.
After preparing the two following xxhdpi images (480 dpi, so to make them scale well - then I put them in the /res/drawable-xxhdpi folder)

当然,我必须仔细调整图像的大小以完美匹配和重叠.

Of course, I had to carefully size the images to fit and overlap perfectly.

和一头白发(你的复制品,发白" - 去饱和 +玩亮度/对比度)

and a white hair (a copy of yours, made "whitish" - desaturate + play with brightness/contrast)

我做了这个布局,其中头发图像与头部重叠:

I made this layout, in which the hair image overlaps the head:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f000"
    >
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/head_xxh"
    />
    <ImageView
        android:id="@+id/imgHair"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/hair_wht_xxh"
    />
    <Button
        android:id="@+id/btnColor"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Random hair color"
        android:onClick="clickHandler"
    />
</RelativeLayout>

这是我使用的代码:

package com.dergolem.abc_2;

import java.util.Random;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;

public class Generic
extends Activity
{
    Random rnd = new Random();

    Button btn = null;
    ImageView img = null;

    @Override
    public void onCreate(final Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.hair);

        img = (ImageView) findViewById(R.id.imgHair);
        btn = (Button) findViewById(R.id.btnColor);
    }

    public void clickHandler(final View v)
    {
        colorize(rnd.nextInt(7));
    }

    private void colorize(final int num)
    {
        int clr = Color.WHITE;
        switch (num)
        {
            case 0:
            {
                clr = Color.RED;
                break;
            }
            case 1:
            {
                clr = Color.GREEN;
                break;
            }
            case 2:
            {
                clr = Color.BLUE;
                break;
            }
            case 3:
            {
                clr = Color.BLACK;
                break;
            }
            case 4:
            {
                clr = Color.CYAN;
                break;
            }
            case 5:
            {
                clr = Color.YELLOW;
                break;
            }
            case 6:
            {
                clr = Color.parseColor("#ff888800");
                break;
            }
        }

        img.setColorFilter(clr, PorterDuff.Mode.MULTIPLY);
    }
}

以及我得到的一些结果:

And some of the results I got:

即使这幅作品看起来像是安迪·沃罗尔的作品,但事实并非如此.这是我的.:)
这似乎是您正在寻找的结果.

Even if this composition seems like an Andy Wharol's picture, it isn't. It's mine. :)
It seems like the result you are looking for.

我没有尝试这个新想法,但是(通过一些额外的工作)您甚至可以更改其他颜色:

I didn't try this new idea, but (with some extra work) you can even change other colors:

  • 眼睛
  • 皮肤
  • 口红
  • 眼妆(这需要一些耐心)

这篇关于在具有某些指定发型图像图案的发型上应用滤色器的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在具有某些指定发型图像图案的发型上应用滤色器的最佳方法是什么?

基础教程推荐