如何在 Android 上访问位图图像的像素?

发布于 2024-10-04 05:10:09 字数 453 浏览 0 评论 0原文

简而言之,我无法访问位图图像的所有像素。

我使用意图来触发本机相机应用程序并将位图图像返回到我的应用程序活动。数据绝对是一个位图对象,我能够显示、获取高度/宽度等并使用 getPixel() 访问一些像素。但是,当我使用 getHeight() 和 getWidth() 的值时,出现数组越界错误。通过反复试验,我发现我只能访问图像的少量像素,例如,对于返回高度和宽度值为 420,380 的一张图像,我还可以访问 200,100。然后我进行一些图像处理并在原始图像上使用 setPixel() 。当我显示图像时,它显示 200,100 个正在处理的像素,其余部分正常,因此像素显然在那里并且可以由 android 访问,但不能由我访问。我必须与其他也遇到此图像问题的人交谈。

有谁知道更多关于这件事的信息,原因吗?或者解决方法?

非常感谢。

似乎没有办法解决这个问题,有人认为使用 NDK 直接在内存中访问图像会更好/可能吗?

In short I am unable to access all the pixels of a bitmap image.

I have used an intent to fire the native Camera app and returned a Bitmap image to my application activity. The data is definitely a bitmap object and I am able to display, get the height/width etc and access some pixels using getPixel(). However when I use the values of getHeight() and getWidth() I get an array out of bounds error. By trail and error I have found I can only access a reduced number of pixels of the image, for example with one image which returned a height and width value of 420,380, I could also access 200,100. I then do some image processing and used setPixel() on the original image. When I display the image it shows the, say 200,100, processing pixels and the rest normal, therefore the pixels are obviously there and accessible by android but not by me. I have to spoken to other people who have also had this problem with images.

Does anyone know anything more about this, reasons? or a work around?

Many thanks in advance.

It seems that there's no way around this, does anyone think it would be better/possible to access the image directly in memory maybe using the NDK?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吃颗糖壮壮胆 2024-10-11 05:10:09

您将无法访问任何图像中 (getWidth(),getHeight()) 处的像素,因为与其他所有内容一样,它们都是 0 索引的。像素的有效范围是(0到getWidth()-1, 0到getHeight()-1),因此最右下角的像素是通过b.getPixel(b.getWidth()-1, b.getHeight()-获得的1)。

You won't be able to access the pixel at (getWidth(),getHeight()) in any image because like everything else they are 0-indexed. The valid range of pixels is (0 to getWidth()-1, 0 to getHeight()-1), and thus the bottomrightmost pixel is obtained by b.getPixel(b.getWidth()-1, b.getHeight()-1).

暖心男生 2024-10-11 05:10:09

在 Android 论坛上得到了 Albert Pucciani 的回答。我现在创建一个 int 缓冲区 并将像素复制到其中,然后使用 get()put() 提取像素。使用 get()put() 而不是 Bitmap 中的 get/setPixel() 也更快代码>类。现在需要测试这是否确实将所有图像的所有像素返回到缓冲区。

经过更多测试后,我发现这只是一个内存问题,因为为每个进程分配的数量包括所有位图。

Got an answer from Albert Pucciani on the Android forums. I now create an int buffer and copy the pixels to it, then use get() and put() to extract the pixels. It's also much quicker to use get() and put() instead of the get/setPixel() from the Bitmap class. Need to test now whether this does return all the pixels to the buffer for all images.

After more testing I have discovered this is simply a memory issue as the amount allocated for each process includes all bitmaps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文