简体   繁体   English

从ARGB BufferedImage获取RGBA像素?

[英]Get RGBA pixels from ARGB BufferedImage?

Is there a simple way to get an rgba int[] from an argb BufferedImage ? 有没有一种简单的方法可以从argb BufferedImage获取rgba int[] I need it to be converted for opengl, but I don't want to have to iterate through the pixel array and convert it myself. 我需要将其转换为opengl,但是我不想遍历像素数组并自己进行转换。

OpenGL 1.2+ supports a GL_BGRA pixel format and reversed packed pixels. OpenGL 1.2+支持GL_BGRA像素格式和反向打包像素。

On the surface BGRA does not sound like what you want, but let me explain. 从表面BGRA并不像您想要的,但让我解释一下。

Calls like glTexImage2D (...) do what is known as pixel transfer, which involves packing and unpacking image data. glTexImage2D (...)类的调用执行所谓的像素传输,涉及打包和解包图像数据。 During the process of pixel transfer, data conversion may be performed, special alignment rules may be followed, etc. The data conversion step is what we are particularly interested in here; 在像素传输过程中,可能会执行数据转换,可能会遵循特殊的对齐规则,等等。 you can transfer pixels in a number of different layouts besides the obvious RGBA component order. 除了明显的RGBA组件顺序之外,您还可以采用多种不同的布局传输像素。

If you reverse the byte order ( eg data type = GL_UNSIGNED_INT_8_8_8_8_REV ) together with a GL_BGRA format, you will effectively transfer ARGB pixels without any real effort on your part. 如果将字节顺序( 例如,数据类型= GL_UNSIGNED_INT_8_8_8_8_REV )与GL_BGRA格式一起GL_BGRA ,则可以有效地传输ARGB像素,而无需您付出任何实际努力。

Example glTexImage2D (...) call: 示例glTexImage2D (...)调用:

glTexImage2D (..., GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image);

The usual use-case for _REV packed data types is handling endian differences between different processors, but it also comes in handy when you want to reverse the order of components in an image (since there is no such thing as GL_ARGB ). _REV打包数据类型的通常用例是处理不同处理器之间的字节序差异,但是当您想要反转图像中组件的顺序时,它也很方便(因为没有GL_ARGB这样的东西)。

Do not convert things for OpenGL - it is perfectly capable of doing this by itself. 不要为OpenGL转换内容-它完全有能力单独执行此操作。

In order to transition between argb and rgba you can apply "bit-wise shifts" in order to convert them back and forth in a fast and concise format. 为了在argb和rgba之间转换,您可以应用“按位移位”,以快速简洁的格式来回转换它们。

argb = rgba <<< 8

rgba = argb <<< 24

If you have any further questions, this topic might should give you a more in-depth answer on converting between rgba and argb. 如果您还有其他问题, 本主题可能会为您提供有关在rgba和argb之间进行转换的更深入的答案。

Also, if you'd like to learn more about java's bitwise operators check out this link 另外,如果您想进一步了解Java的按位运算符, 请查看此链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM