什么是应用彩色滤光片的发型与一些特定的发型图像模式的最好方法是什么? [英] What is the best way to apply color filter on hair style with some specified hair style image pattern?
问题描述
我开发一个Android应用程序的发型salon.I我有两个图像。一个是发型(发型),另一种是发色图案。 我能够改变发型基于特定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.
我的code是如下:
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.
推荐答案
只是为了好玩,和好奇,我试图让我自己的实现你的想法。
preparing以下两个xxhdpi映像(480 dpi的,所以让他们很好地扩展 - 然后我把它们放在 / RES /绘制-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>
这里的code我用:
Here's the code I used:
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);
}
}
和一些我得到的结果:
即使此组合物似乎是一种安迪Wharol相关图片,事实并非如此。是我的。 :)
好像你正在寻找的结果。
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:
- 眼睛
- 皮肤
- 唇膏
- 在眼妆(这将需要一些耐心)
这篇关于什么是应用彩色滤光片的发型与一些特定的发型图像模式的最好方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!