在Android中访问JPEG图像的单独像素
在我的 android 项目中,我需要访问 JPEG 图像的每个单独像素。由内置照片应用程序创建的图像。我尝试将 JPEG 转换为 Bitmap
类实例,但抛出了 OutOfMemoryException
。在搜索有关此问题的信息后,我找到了以下解决方案:调整图像大小!但图像质量在我的项目中很重要,而且我无法调整它的大小。有什么办法可以访问每个像素吗?
In my android project I need to get access for each separate pixel of JPEG image. Image created by built-in photo application. I try to convert JPEG into Bitmap
class instance, but OutOfMemoryException
was thrown. After searching info about this problem I have found the following solution: resize image! But quality of image is important in my project, and i can't resize it. Is there any way to get each-pixel access?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的图像太大并且质量很重要,我想最好的方法是使用或创建您自己的类来剪切区域中的图像(例如:50*50 px),互联网上有几个 jpeg 信息类可以提供帮助您了解 jpeg 文件的工作原理。
您尝试过 BufferedImage 吗? (它不在sdk中,但也许可用)
if your image is too big and the quality is important i suppose the best way is to use or create your own class to cut the image in zone (eg : 50*50 px) , there is several jpeg info class in the internet to help you understand how work jpeg files.
Have you tried BufferedImage ? (it's not in the sdk but maybe usable)
jpeg 的性质使得获取单个像素的值非常困难。主要原因是数据不是字节对齐的,另一个原因是所有内容都编码在大小为 8x16、16x8 和 8x8 的块中。此外,您还需要处理色度值的子采样。
如果图像包含重新启动标记,也许您可以跳到图像,这样您就不必在获取像素值之前解码整个图像。
The nature of jpeg makes it very hard to get the value of a single pixel. The main reason is that the data is not byte aligned, another is that everything is encoded in blocks that can be of sizes 8x16, 16x8 and 8x8. Also, you need to handle subsampling of chroma values.
If the image contains restart markers, maybe you can skip into the image so you don't have to decode the whole image before getting the pixel value.