Android 如何根据布局背景图像颜色更改图像反箭头颜色?
在上面的代码中,Android 如何根据布局背景图像颜色更改图像反箭头颜色?,android,Android,在上面的代码中,itemUserProfileBinding.ivItemUserProfile是我的背景图像视图,itemUserProfileBinding.ivUserProfileBackArrow这是我的自定义工具栏后退箭头图像视图 我试过上面的方法,但不起作用,有人能帮我吗 提前感谢我没有正确理解您的问题,但是如果您想反转整个位图,请获取图像中的每个像素,然后反转其RGB值 如果itemUserProfileBinding.ivUserProfileBackArrow是您的image
itemUserProfileBinding.ivItemUserProfile
是我的背景图像视图,itemUserProfileBinding.ivUserProfileBackArrow
这是我的自定义工具栏后退箭头图像视图
我试过上面的方法,但不起作用,有人能帮我吗
提前感谢我没有正确理解您的问题,但是如果您想反转整个位图,请获取图像中的每个像素,然后反转其RGB值
如果itemUserProfileBinding.ivUserProfileBackArrow是您的imageview,那么我认为您应该首先从imageview获取位图,然后反转该位图的颜色,然后将反转后的位图设置为imageview。您可以使用调色板类生成颜色并相应地更改它
Bitmap bitmap = ((BitmapDrawable)itemUserProfileBinding.ivItemUserProfile.getDrawable()).getBitmap();
// Bitmap imageProfile = BitmapFactory.decodeResource(activity.getResources(),arrayList.get(position).getProfile());
int pixel = bitmap.getPixel(20,20);
int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);
int invertedRed = 255 - redValue;
int invertedGreen = 255 - greenValue;
int invertedBlue = 255 - blueValue;
itemUserProfileBinding.ivUserProfileBackArrow.setColorFilter(Color.argb(255, invertedRed, invertedGreen, invertedBlue));
但它不工作
它做什么?它到底是如何不起作用的?这并不能回答这个问题。一旦你有足够的钱,你将能够;相反
//Gradle dependency
dependencies {
compile 'com.android.support:palette-v7:2x.x.x'
}
// Java
Palette.from(bitmap).generate(new PaletteAsyncListener() {
public void onGenerated(Palette p) {
// Use generated instance
// this is an Async call, You will get following colors in respect to bitmap
/*Vibrant
Vibrant Dark
Vibrant Light
Muted
Muted Dark
Muted Light*/
itemUserProfileBinding.ivUserProfileBackArrow.setColorFilter(p.getMuted(0x000000));
}
});