【问题标题】:Issue applying ColorFilter on image view在图像视图上应用 ColorFilter 的问题
【发布时间】:2019-01-10 17:26:54
【问题描述】:

我正在开发图像过滤器应用程序并遇到问题。 所以我想知道如何在图像视图上应用颜色、饱和度和亮度? (请考虑我的图像视图只有一种纯色)

颜色:

 public void setImageColor(int color) {
        image.setColorFilter(color);
    }

饱和度:

 public void setSaturationBitmap(int saturation) {
        image.setDrawingCacheEnabled(true);
        image.buildDrawingCache();
        Bitmap bm = image.getDrawingCache();
        Bitmap alteredBitmap = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), bm.getConfig());
        Canvas canvas = new Canvas(alteredBitmap);
        Paint paint = new Paint();
        paint.reset();
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(satur);
        paint.setColorFilter(image.getColorFilter());
        paint.setColorFilter(new ColorMatrixColorFilter(cm));
        Matrix matrix = new Matrix();
        canvas.drawBitmap(bm, matrix, paint);
        image.setImageBitmap(alteredBitmap);}

谢谢。

【问题讨论】:

  • 代码是必需的。分享吧。
  • 您可能想要扩展 ImageView,并覆盖 onDraw 方法,并在调用 super.onDraw() 后应用您的过滤器
  • final int semiTransparentGrey = Color.argb(155, 185, 185, 185); drawable.setColorFilter(semiTransparentGrey, PorterDuff.Mode.SRC_ATOP);
  • 你可以看到我编辑的问题@Piyush
  • 在我的情况下,饱和度工作正常,但是当我改变颜色时,我无法应用饱和度@VladyslavMatviienko

标签: android imageview colorfilter


【解决方案1】:

您可以编辑位图并在图像视图中使用它:

在 SOF 上关注此帖子: https://stackoverflow.com/a/35055244/7147289

【讨论】:

  • 带有指向另一个答案的链接的答案永远不会很好。要么使用评论,要么写一个完整的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-07
  • 1970-01-01
  • 2016-07-01
相关资源
最近更新 更多