在 Android 中将位图转换为灰度 [英] Convert a Bitmap to GrayScale in Android

查看:32
本文介绍了在 Android 中将位图转换为灰度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是这个网站的新手,我有一个关于 Android 的问题.

I am new to this site, and I come with a question about Android.

有没有办法将位图转换为灰度?我知道如何绘制灰度位图(使用画布操作:http://www.mail-archive.com/android-developers@googlegroups.com/msg38890.html)但我真的需要灰色的实际位图(或者至少可以在以后转换为位图的东西).我是否必须手动实现(逐像素操作)?

Is there any way to convert a Bitmap to grayscale? I know how to draw a grayscale bitmap (using canvas operations: http://www.mail-archive.com/android-developers@googlegroups.com/msg38890.html) but I really need The actual bitmap in gray colors (or at least something that could be converted to a bitmap later on). Do I have to implement it by hand (pixel by pixel operations)?

我找了很多,还是没找到.有人知道一种简单/有效的方法吗?

I've searched a lot, and still could not find. Anyone knows a easy/efficient way to do it?

非常感谢!

推荐答案

这不正是您所链接的代码所做的吗?它需要一个颜色位图(bmp"),创建一个重复的位图(bm"),然后使用过滤器将颜色位图绘制到bm"中,将其转换为灰度.从那时起,您可以将bm"用作实际的灰度位图,并对其进行任何您想做的事情.

Isn't that exactly what the code you're linking to does? It takes a color bitmap ("bmp"), creates a duplicate bitmap ("bm"), and then draws the color bitmap into "bm" using the filter to turn it into grayscale. From that point on, you can use "bm" as an actual grayscale bitmap and do whatever you want to do with it.

您需要稍微调整样本(它使用硬编码大小,您可能只想克隆原始位图的大小),但除此之外,这似乎是随时可用的取决于你想要什么.

You'd need to tweak the sample a bit (it's using hard-coded sizes, you may want to just clone the size of the original bitmap), but other than that, this seems to be as ready-to-use as it gets, depending on what you want.

这篇关于在 Android 中将位图转换为灰度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆