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

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

问题描述

我是新来这个网站,我带着一个关于Android的问题。

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

有没有什么办法可以转换为位图到灰度?我知道如何绘制灰度位图(用帆布操作:<一href="http://www.mail-archive.com/android-developers@googlegroups.com/msg38890.html">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?

非常感谢!

推荐答案

这不正是你要链接到code呢?这需要一种颜色的位图(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.

您会需要调整采样位(它使用硬codeD的大小,您可能希望只克隆原来的位图的大小),但除此之外,这似乎是因为现成易于使用的,因为它得到,这取决于你想要什么。

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天全站免登陆