gpt4 book ai didi

java - 灰度图像显示红色 - android

转载 作者:行者123 更新时间:2023-11-30 01:50:19 25 4
gpt4 key购买 nike

我有一些奇怪的问题。我从 int[] 像素数组设置灰度 Bitmap。所以我把这个

    bitmap = Bitmap.createBitmap(512, 512, Bitmap.Config.ARGB_8888);
byte[] byteArray = new String(pixelsArray).getBytes("UTF-8");
Bitmap bitmap = getBitmapFromByte(byteArray, pixelsArray.length);
ImageView theImage = (ImageView) findViewById(R.id.echo);
theImage.setImageBitmap(bitmap);

问题是我得到了正确的图像,但是是红色的。所以我认为这与保存位图的 ImageView 包装器有关。

<LinearLayout
android:id="@+id/some_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/theme_blue"
android:orientation="vertical">

<ImageView
android:id="@+id/echo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/some_image" />

所以我把

LinearLayout linearLayout = (LinearLayout)findViewById(R.id.vMiddle);
linearLayout.setBackgroundColor(Color.BLACK);

但它仍然显示为红色。有人有想法吗?顺便说一句,我在测试纯 Java 应用程序上测试了 int[] 像素数组,它可以正确显示灰度颜色。

最佳答案

使用 ColorMatrix 和 ColorMatrixColorFilter 将 ImageView 的内容设置为灰度。

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

ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);

然后简单地设置 ImageView 以使用过滤器。

ImageView imageView = (ImageView)findViewById(R.id.imageView);
imageView.setColorFilter(filter);

这将使 ImageView 的内容变为灰度。

关于java - 灰度图像显示红色 - android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33161073/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com