【问题标题】:Transparent Color Effect Over the Image Bitmap in AndroidAndroid中图像位图的透明颜色效果
【发布时间】:2013-11-18 17:38:57
【问题描述】:

我正在开发一个图像编辑器 android 应用程序,例如:BeFunkey 我已经实现了很多类似这个 android 应用程序的效果,但仍然有一些效果让我头疼。像波普艺术效果。请看下面的图片。一是原创,二是popart彩色效果:

原创 ::

波普艺术 ::

我使用 RGB 颜色矩阵来获得位图的颜色效果。但是当我使用它时,它就像整个图像中的一种颜色,但在这种效果中,图像上有多种颜色。如果有人可以指导我,请告诉我如何实现这种颜色效果。感谢您的宝贵时间。

以下我用于颜色效果的代码::

    public static final float[] float_color_matrix = new float[] { 2.6f, 0, 0.1f, 0, 0, 0.1f, 1.2f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 };

    ColorMatrix cm = new ColorMatrix();
    cm.postConcat(new ColorMatrix(float_color_matrix));
    ColorFilter colorFilter = new ColorMatrixColorFilter(cm);

    imageView.setColorFilter(colorFilter);

【问题讨论】:

  • 请张贴代码,说明您是如何应用效果的。
  • @Neil...请看帖子我已经用代码更新了它...
  • 您还需要显示您的 float_color_matrix 数组。这就是我想看到的
  • // // 图片 2 public static final float[] float_color_matrix = new float[] { 2.6f, 0, 0.1f, 0, 0, 0.1f, 1.2f, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 };
  • 我认为您无法使用 ColorFilter 来实现此效果

标签: android image-processing


【解决方案1】:

这段代码应该可以解决问题。我非常接近您正在寻找的结果。如果不完全一样,您可以使用 colors 数组中的颜色。我使用this 漂亮的工具来查找十六进制颜色代码。

/**
 * 
 * @param context
 * @param yourDrawableResource (ex R.drawable.ic_drawable)
 * @return the image bitmap with the correct overlay
 */
public static Bitmap setPopArtGradient(Context context, int yourDrawableResource) {
    int[] colors = new int[]{Color.parseColor("#FFD900"),Color.parseColor("#FF5300"),
                             Color.parseColor("#FF0D00"),Color.parseColor("#AD009F"),
                             Color.parseColor("#1924B1")};
    float[] colorPositions = new float[]{0.2f,0.4f,0.6f,0.8f,1.0f};

    final Resources res = context.getResources();
    Drawable drawable = res.getDrawable(yourDrawableResource);

    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap); 
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    /* Create your gradient. */
    LinearGradient grad = new LinearGradient(0, 0, 0, canvas.getHeight(), colors, colorPositions, TileMode.CLAMP);

    /* Draw your gradient to the top of your bitmap. */
    Paint p = new Paint();
    p.setStyle(Style.FILL);
    p.setAlpha(110); //adjust alpha for overlay intensity
    p.setShader(grad);
    canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), p);

    return bitmap;
}

然后你只需通过这样做来实现它

imageView.setImageBitmap(setPopArtGradient(yourContext, R.drawable.your_drawable));

如果你想传递一个位图,你可以这样做。

/**
 * 
 * @param context
 * @param bmp (your bitmap)
 * @return the image bitmap with the correct overlay
 */
public static Bitmap setPopArtGradientFromBitmap(Context context, Bitmap bmp) {
    int[] co = new int[]{Color.parseColor("#FFD900"),Color.parseColor("#FF5300"),Color.parseColor("#FF0D00"),Color.parseColor("#AD009F"),Color.parseColor("#1924B1")};
    float[] coP = new float[]{0.2f,0.4f,0.6f,0.8f,1.0f};

    Bitmap bitmap = bmp.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(bitmap);

    /* Create your gradient. */
    LinearGradient grad = new LinearGradient(0, 0, 0, canvas.getHeight(), co, coP, TileMode.CLAMP);

    /* Draw your gradient to the top of your bitmap. */
    Paint p = new Paint();
    p.setStyle(Style.FILL);
    p.setAlpha(110);
    p.setShader(grad);
    canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), p);

    return bitmap;
}

我将它应用到我拍摄的一张照片上,这就是结果

希望对你有帮助。

【讨论】:

  • 你好兄弟,我想传递 Bitmap 而不是 int yourDrawableResource,所以我需要做些什么改变......???
猜你喜欢
  • 2013-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-06
  • 2013-01-15
  • 1970-01-01
  • 2012-05-07
  • 2012-10-21
相关资源
最近更新 更多