在Android图像处理 [英] Image Processing on Android
问题描述
我正在写为Android应用程序。 我需要一些图像处理上的照相机拍摄的图像。 我用Camera.PictureCallback拿到照片,我也得到画面的字节数组。 问题是我想在照片(一些过滤和其他的东西),所以我猜的每一个像素地进行操作,具有照片中的字节数组是不是一个坏主意。但我不知道在这个字节数组...如何跨preT的信息,我知道只有这样,才能使处理使用BitmapFactory.de codeByteArray(),然后使用位图对象。这是一个很好的方法来处理大量的图像处理的? 现在,我使用的东西是这样的:
I'm writing an application for Android. I need to make some image processing on the picture taken from camera. I use Camera.PictureCallback to get the photo, and I get picture in byte array. The problem is I want to make operations on every pixel of photo (some filtering and other stuff) so I guess, have photo in byte array is not a bad idea. But I don't know how interpret information in this byte array... The only way I know to make the processing is use BitmapFactory.decodeByteArray() and then use Bitmap object. Is this a good way to handle a lot of image processing? Right now I use something look like this:
位图mPhotoPicture mPhotoPicture = BitmapFactory.de codeByteArray(为imageData,0,imageData.length);
Bitmap mPhotoPicture mPhotoPicture = BitmapFactory.decodeByteArray(imageData, 0 , imageData.length);
mPhotoPicture = mPhotoPicture.copy(Bitmap.Config.RGB_565,真);
mPhotoPicture = mPhotoPicture.copy(Bitmap.Config.RGB_565, true);
我AP preciate任何帮助。
I appreciate any help.
推荐答案
我不知道,如果解码成字节数组是做它在Android的最佳途径,但我可以提供我所知道的一般图像处理
I'm not sure if decoding into a byte array is the best way to do it on Android, but I can offer what I know about image processing in general.
如果您使用的是 RGB_565
,这意味着每个像素是16位,或两个的字节。前5比特是红色的,接下来的6是绿色的,而最后5是蓝色的。与该交易是毛茸茸的Java编写的。我建议你用一个更简单的格式,如 ARGB_8888
,这将意味着你有32位,或每个像素的四个字节的工作,每一个字节是其本身的价值(Alpha,红色,绿,蓝)。
If you're using RGB_565
, that means each pixel is 16 bits, or two of those bytes. The first 5 bits are red, the next 6 are green, and the last 5 are blue. Dealing with that is hairy in Java. I suggest you work with an easier format like ARGB_8888
, which will mean you have 32 bits, or four bytes per pixel, and each byte is its own value (alpha, red, green, blue).
要测试,尝试设置4个字节,如 [3]
, [7]
, [11]
,系统等,为0。这应该采取了所有特定频道的,在这种情况下,所有的蓝
To test, try setting every fourth byte, like [3]
, [7]
, [11]
, etc., to 0. That should take out all of a particular channel, in this case, all the blue.
[2]
, [6]
, [10]
等,将所有的绿色价值观为每个像素。
[2]
, [6]
, [10]
, etc. would be all the green values for each pixel.
(注意,这四个组件可能以相反的顺序走,因为我不知道字节排列顺序!所以,我可能刚才告诉你如何取出α,不是蓝色的...)
(Note, the four components might go in the opposite order because I'm not sure about endianness! So I might have just told you how to take out the alpha, not the blue…)
这篇关于在Android图像处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!