BufferedImage 中通道的顺序?
如何找出 BufferedImage 中颜色通道的顺序(不同类型,包括 Alpha 通道)?
我需要知道 LookupOp(ByteLookupTable(int, byte[][]) 中 byte[][] 的顺序)或 RescaleOp(float[], float[],hints 等操作的 R、G 和 B 参数的顺序)。
是否有一种通用方法可以从给定的 BufferedImage 中查找顺序?我认为它应该在 ColorModel 中,但我找不到它。
我使用过像 if (t == BufferedImage.TYPE_INT_ARGB)
这样的代码,但一定有更好的方法,对吗?
How do I find out the order of color channels in a BufferedImage (different types including alpha channels)?
I need to know the order of R, G, and B parameters for operations like LookupOp (order of byte[][] in ByteLookupTable(int, byte[][])) or RescaleOp(float[], float[], hints).
Is there a generic way to find the order from a given BufferedImage? I thought it should be in the ColorModel but I can't find it.
I have used code like if (t == BufferedImage.TYPE_INT_ARGB)
but there must be better ways, right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你正在寻找的东西分为
SampleModel 和 ColorModel。
SampleModel
描述了数据的组织方式,使您能够获取一个或多个像素的数据。 (您可以通过调用bi.getData().getSampleModel(),
来获取SampleModel
,其中 bi 是 BufferedImage)。ColorModel
然后提供方法(getAlpha
、getRed
、getGreen
、GetBlue
)来获取来自像素的 ARGB 分量。附录:
我认为您使用它的方式是:
这看起来对于处理您可能遇到的任何颜色/样本模型都非常灵活,但我无法想象性能会非常出色。我可能会使用这种与模型无关的方法将图像转换为 TYPE_INT_ARGB ,其中布局有详细记录,然后直接操作数据。然后,如有必要,将其转换回原始形式。
I think what you're looking for is split between
SampleModel and ColorModel.
The
SampleModel
describes how the data is organized which allows you to get the data for one or more pixels. (You get aSampleModel
by callingbi.getData().getSampleModel(),
where bi is a BufferedImage).ColorModel
then provides methods (getAlpha
,getRed
,getGreen
,GetBlue
) for getting the ARGB components from a pixel.Addendum:
I think the way you use this is:
This looks like it would be very flexible for handling any color/sample model you may encounter, but I can't imagine the performance would be spectacular. I'd probably use this model agnostic approach to convert the image to
TYPE_INT_ARGB
where the layout is well documented, then manipulate the data directly. Then, if necessary, convert it back to the original form.