android– 使用一些指定的发型图像模式在头发样式上应用滤色器的最佳方法是什么?

android– 使用一些指定的发型图像模式在头发样式上应用滤色器的最佳方法是什么?,第1张

概述我正在为发型沙龙开发一个Android应用程序.我有两个图像.一个是发型(头发),另一个是头发颜色图案.我能够根据特定的rgb值更改发型的颜色.我的代码如下:intcolor=Color.rgb(182,132,84);//gettingrgbvaluePaintpaint=newPaint();paint.setColorFilter(newLightin

我正在为发型沙龙开发一个Android应用程序.我有两个图像.一个是发型(头发),另一个是头发颜色图案.
我能够根据特定的rgb值更改发型的颜色.

我的代码如下:

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值.

喜欢:

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

解决方法:

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

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

 和一头白发(你的副本,制作“发白” – 用亮度/对比度去饱和的游戏)

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

<?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 Genericextends 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);    }}

我得到的一些结果:

   

即使这个构图看起来像Andy Wharol的照片,也不是.这是我的. 总结

以上是内存溢出为你收集整理的android – 使用一些指定的发型图像模式在头发样式上应用滤色器的最佳方法是什么?全部内容,希望文章能够帮你解决android – 使用一些指定的发型图像模式在头发样式上应用滤色器的最佳方法是什么?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1117983.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存