It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center




8年前关闭。




我正在使用纹身应用程序,因为我需要将图像(从相机拍摄或从图库中选择)转换为纹身...

我的要求如下

我从github找到了一个示例代码https://github.com/DrewDahlman/ImageFilter/tree/master/Android/project
它用于图像过滤..

我不知道将图像转换为纹身的过程是否正确

如果有人知道android中的这个纹身,请建议我,我在谷歌上搜索了很多

提前致谢..

最佳答案

你需要一个差异过滤器:

1)你计算水平差异(在这里你会有垂直段)

2)你计算垂直差异(这里是水平段)

3)你或两张 map ,找到轮廓

4) 重新创建一个 Bitmap 对象,如果你愿意的话

类似(已编辑):

int[] pixels;
int width = yourbitmap.getWidth();
int height = yourbitmap.getHeight();
yourbitmap.getPixels(pixels, 0, width, 0, 0, width, height);

// transform grayscale
int[] image = new int[width*height];
for (int y=0; y<height; y++)
    for (int x=0; x<width; x++)
    {
        int pixel = image[y*width + x];
        image[y*width + x] = (Color.red(pixel) + Color.green(pixel) + Color.blue(pixel))/3;
    }

// calculate diff_x (vertical segments)
int[] dx = new int[width*height];

for (int y=0; y<height; y++)
    for (int x=0; x<width; x++)
        dx[y*width + x] = (x==0 || y== 0 ? 0 : Math.abs(image[y*width + x] - image[y*width + x-1]));

// calculate diff_y (horizontal segments)
int[] dy = new int[width*height];

for (int y=0; y<height; y++)
    for (int x=0; x<width; x++)
        dy[y*width + x] = (x==0 || y== 0 ? 0 : Math.abs(image[y*width+x] - image[(y-1)*width+x]));


// when the color intensity is higher than THRESHOLD, accept segment
// you'll want a slider to change THRESHOLD values
bool[] result = new bool[width*height];
const int THRESHOLD = 60; // adjust this value

for (int y=0; y<height; y++)
    for (int x=0; x<width; x++)
        result[y*width + x] = (dx[y*width + x] > THRESHOLD || dy[y*width + x] > THRESHOLD);

Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
for (int y=0; y<height; y++)
    for (int x=0; x<width; x++)
               result.setPixel(x, y, result[y*width+x]? Color.Black : Color.White);

关于android - 如何将图像转换为纹身?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15610609/

10-09 04:09