检测我的位图是黑白还是颜色图像
我有一个图像URI,我使用以下代码从该URI获取bitmap
:
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(getContext().getContentResolver(), uri);
} catch (IOException e) {
e.printStackTrace();
}
现在我想检查bitmap
是黑色和白色还是颜色图像。
(要么有黑色/白色图像或彩色图像)
我该怎么做? 我在Android上使用Java。
I have an image URI and I am getting the Bitmap
from that URI using the code below:
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(getContext().getContentResolver(), uri);
} catch (IOException e) {
e.printStackTrace();
}
Now I want to check if the Bitmap
is a black and white or a color image.
(There will either be a black/white image or a colored one)
How can I do this?
I am using Java on Android.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在Kotlin中创建了一个扩展功能,您可以使用此功能或在Java中以相同逻辑制作类似的函数
来使用扩展功能,只需调用
iScolored = yourbitmap.iscolored()
edit:java函数
编辑: Java的主要活动显示其使用
I created an extension function in kotlin, you can use this or make a similar function in java with same logic
to use an extension function just call
isColored = yourBitmap.isColored()
Edit: java function
Edit 2: Main activity in java showing its use