【问题标题】:Android Palette: Why not working with this particular image?Android Palette:为什么不使用这个特定的图像?
【发布时间】:2014-11-07 07:14:54
【问题描述】:

我目前正在使用支持库 (https://developer.android.com/tools/support-library/features.html#v7-palette) 中的 Palette API

下面的代码可以很好地处理数百张图片,完全没有问题。我根据调色板结果设置文本和背景颜色。结果非常棒,而且看起来非常漂亮(如果您想在您的应用程序中重复使用它,请不要犹豫!)。

不幸的是,在数百张图片中,只有一张无法正常工作并给出奇怪的结果。 就是这个=>http://www.cineswellington.com/images/film/140929075044.jpg

由于调色板没有文档或调试模式,我真的很想知道会发生什么,以及是否有办法了解原始图片是否存在缺陷或其他什么。

Picasso.with(getActivity()).load("http://www.cineswellington.com/images/film/140929075044.jpg").into(t);

private Target t = new Target() {
    @Override
    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
        Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
            public void onGenerated(Palette palette) {
                ((ImageView) v.findViewById(R.id.iv)).setImageDrawable(new BitmapDrawable(bitmap));
                //At this point, the ImageView is correctly filled, so the bitmap object has no issue.
                int textColor = palette.getLightMutedColor(android.R.color.darker_gray);
                int bgColor = palette.getDarkMutedColor(android.R.color.white);
                Log.d("CVE","textColorInt: "+ textColor);
                Log.d("CVE","bgColorInt: "+bgColor);
                Log.d("CVE","textColorHexa: "+String.format("#%06X", 0xFFFFFF & textColor));
                Log.d("CVE","bgColorHexa: "+String.format("#%06X", 0xFFFFFF & bgColor));
            }
        });


    }
};

这是输出:

textColorInt: 17170432
bgColorInt: 17170443
textColorHexa: #060000
bgColorHexa: #06000B

如果有人可以帮助我重现错误或告诉我它只发生在我身边,那就太棒了

【问题讨论】:

  • 能否请您也给出正确的示例结果
  • 正确的例子是用互联网上的任何图片制作的,结果是标准颜色(蓝色变化、红色、绿色等)。

标签: android android-support-library palette


【解决方案1】:

图像似乎只包含鲜艳的颜色,因此很难创建适合它的柔和调色板。算法失败并不奇怪。

如果柔和的暗/亮太相似,请尝试使用 getVibrantColor() 函数。

【讨论】:

  • 静音颜色不为空,发送了一些结果...而事件如果为空,则有我指定的默认颜色...
  • 可能有一些颜色在静音范围内(由于透明的红色火焰),所以那些被返回。我猜它只是返回调色板中处于静音范围内的最暗和最亮的颜色
【解决方案2】:

我猜在调色板算法中,“浅色柔和”和“深色柔和”颜色之间没有最小的颜色差异,即不应该将一种颜色用作另一种颜色。

在 Romain Guy 在 Google IO 的演示中,他使用“轻柔”作为背景,使用“轻亮”作为文本颜色。

您不应该为您的文本使用鲜艳的颜色吗?

【讨论】:

    猜你喜欢
    • 2015-01-05
    • 1970-01-01
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多