0

你好,有灰度图像背景的方法吗?我实现了灰度图像本身,但不是背景:/。

我的 GridView 获取视图:

// create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;

        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(65, 65));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(13, 13, 13, 13);


        } else {
            imageView = (ImageView) convertView;

        }
        ColorMatrix matrix = new ColorMatrix();
        matrix.setSaturation(0);

        ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);

        imageView.setImageResource(MainActivity.mThumbIds.get(position));
        imageView.setBackgroundResource(R.drawable.check);
        imageView.setColorFilter(filter);

        return imageView;
    }
4

1 回答 1

1

不是直接的,但您可以将资源渲染到位图,将过滤器应用于位图,并使用 aBitmapDrawable和将背景设置为过滤后的位图imageView.setBackground(Drawable)

于 2013-11-05T14:40:10.923 回答