Android:如何做这个框架涂料? [英] Android: How to do this framing paint?

查看:31
本文介绍了Android:如何做这个框架涂料?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些静态图片,如下所示:

I Have Some static images like below:

现在,我想要的是,当我触摸脸部或手部时,应该在该皮肤部分填充所选颜色.

Now, I want is, when i touch on the face or hand, then the selected color should be fill on that skin portion.

见下图:

那么如何得到如上的结果??重做和撤消功能也应该存在.

So how to get the result like above ?? Redo and Undo Functionality Should be also there.

我曾尝试使用 FloodFill 颜色,但这样做我只能对垂直部分进行着色.因为 FloodFill 只填充颜色,直到出现相同的 pixwl 颜色.如果触摸位置像素颜色发生变化,则不会在其上填充颜色.

I have try with the FloodFill color but doing that i can only able to do color in to the perticular portion. as FloodFill only fill the color till the same pixwl color comes. If the touch place pixel color get change the it will not fill color on it.

所以 Usinf FloodFill 我得到了如下图所示的结果,如果我按下手,那么只有手部会填充颜色,而不是我想为另一只手和脸填充颜色.

So Usinf FloodFill i got the result like below image, If i press on the hand, then only hand portion will fill with color, instead of it i want to fill color to the other hand and face also.

所以请在这种情况下帮助我.

So Please help me in this case.

已编辑

经过一些回复后,我得到了这个之类的解决方案.

After some reply i got the solution like this one.

但仍然存在内存问题.绘制颜色会消耗大量内存.所以请问有人可以帮我吗?

But still there is a memory issue. It consume lots of memory to draw the color. So please can anyone help me for it ?

推荐答案

你可以让一个完整的图像以实际的方式着色,当你用某种颜色填充某个区域时,它将替换该颜色指定的所有区域待填写.

You can have a complete image colored the actual way and when you fill a certain region with a color, it will replace all the regions that is specified by that color to be filled in.

外行条款:

  1. 用户将点击大纲的手
  2. 该点击位置将与另一张具有完美颜色编码区域的图像进行检查.对于这种情况,让我们称其为 MASK.所有皮肤区域都将具有相同的颜色.衬衫区域将是另一种颜色.
  3. 无论用户点击何处,用户选择的颜色都会应用于 MASK 中具有相似颜色的每个像素,但不是直接在 MASK 上绘制,而是绘制到 OUTLINE 的像素上.

我希望这会有所帮助.

如果你想要一个例子,请随时发表评论,然后我可以用它更新答案,但我认为你可以从这里得到它.

Feel free to comment if you want an example and then I can update the answer with that, but I think you can get it from here.

基本上从像这样的简单图像开始.这我们可以称之为OUTLINE

Basically start off with a simple image like this. This we can call as OUTLINE

那么作为开发人员,您必须做一些工作.在这里,您可以对大纲进行颜色编码.我们将结果称为 MASK.为此,我们使用您想要的相同颜色对区域进行颜色编码.这可以在油漆或其他任何东西上完成.我用 Photoshop 很酷 :D.

Then as the developer, you have to do some work. Here, you color code the OUTLINE. The result we call a MASK. To make this we, color code the regions with the same color that you want. This can be done on paint or whatever. I used Photoshop to be cool lol :D.

然后是算法让它在手机上工作.在阅读代码之前,先看看这个变量.

Then there is the ALGORITHM to get it working on the phone. Before you read the code, look at this variable.

int ANTILAISING_TOLERANCE = 70; //Larger better coloring, reduced sensing

如果您放大图像,特别注意边框的黑色区域,您实际上可以看到,有时计算机会稍微混合颜色.为了说明这种变化,我们使用了这个容差值.

If you zoom up on the image specifically noting the black regions of the border, you can actually see that sometimes, the computer blends the colors a little bit. In order to account for that change, we use this tolerance value.

COLORINGANDROIDACTIVITY.JAVA

package mk.coloring;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.view.View.OnTouchListener;

public class ColoringAndroidActivity extends Activity implements OnTouchListener{
    /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    findViewById(R.id.imageView1).setOnTouchListener(this);
}

int ANTILAISING_TOLERANCE = 70;
public boolean onTouch(View arg0, MotionEvent arg1) {
    Bitmap mask = BitmapFactory.decodeResource(getResources(), R.drawable.mask);
    int selectedColor = mask.getPixel((int)arg1.getX(),(int)arg1.getY());           
    int sG = (selectedColor & 0x0000FF00) >> 8;
    int sR = (selectedColor & 0x00FF0000) >> 16;
    int sB = (selectedColor & 0x000000FF);

    Bitmap original = BitmapFactory.decodeResource(getResources(), R.drawable.empty);       
    Bitmap colored = Bitmap.createBitmap(mask.getWidth(), mask.getHeight(), Config.ARGB_8888);
    Canvas cv = new Canvas(colored);
    cv.drawBitmap(original, 0,0, null);

    for(int x = 0; x<mask.getWidth();x++){
        for(int y = 0; y<mask.getHeight();y++){
            int g = (mask.getPixel(x,y) & 0x0000FF00) >> 8;
            int r = (mask.getPixel(x,y) & 0x00FF0000) >> 16;
            int b = (mask.getPixel(x,y) & 0x000000FF);
            if(Math.abs(sR - r) < ANTILAISING_TOLERANCE && Math.abs(sG - g) < ANTILAISING_TOLERANCE && Math.abs(sB - b) < ANTILAISING_TOLERANCE)
                colored.setPixel(x, y, (colored.getPixel(x, y) & 0xFF000000) | 0x00458414);
        }
    }
    ((ImageView)findViewById(R.id.imageView1)).setImageBitmap(colored);

    return true;
}

}

这段代码没有为用户提供很多颜色选择.相反,如果用户触摸某个区域,它会查看MASK 并相应地绘制大纲.但是,您可以制作非常有趣和互动的作品.

This code doesn't provide the user with much of color choices. Instead, if the user touches a region, it will look at the MASK and paint the OUTLINE accordingly. But, you can make really interesting and interactive.

结果

当我摸到那个男人的头发时,它不仅染了头发,还把他的衬衫和手染成了同样的颜色.将其与 MASK 进行比较,以了解发生的情况.

When I touched the man's hair, it not only colored the hair, but colored his shirt and hand with the same color. Compare it with the MASK to get a good idea of what happened.

这只是一个基本的想法.我创建了多个位图,但实际上并不需要.我将它用于测试目的并占用了不必要的内存.而且您不需要在每次点击时重新创建蒙版,等等.

This is just a basic idea. I have created multiple Bitmaps but there is not really a need for that. I had used it for testing purposes and takes up unnecessary memory. And you don't need to recreate the mask on every click, etc.

希望对你有帮助:D

祝你好运

这篇关于Android:如何做这个框架涂料?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆