简体   繁体   English

Java DataBuffer类的原因是什么?

[英]What is the reason for the Java DataBuffer class?

When I was about to investigate the internal implementation of the BufferedImage class in Java, I came across the DataBuffer . 当我要研究Java中BufferedImage类的内部实现时,遇到了DataBuffer The DataBuffer is in finally used to save the blank image data, which can only be interpreted with the related ColorModel and SampleModel implementation. 最后使用DataBuffer保存空白图像数据,该数据只能用相关的ColorModelSampleModel实现来解释。 However, I do not understand the real purpose of the DataBuffer beside of the fact, that it wraps arrays of the same type with some read and write helpers. 但是,除了事实之外,我不了解DataBuffer的真正用途,因为它用一些读写助手包装了相同类型的数组。

DataBuffer is an abstraction, so that BufferedImage does not need to know about actual pixel storage. DataBuffer是一个抽象,因此BufferedImage不需要了解实际的像素存储。

Pixels are usually stored in arrays, but it can be a single packed or interleaved array, or it can be a single or multiple banded arrays. 像素通常存储在阵列中,但是可以是单个打包或交错的阵列,也可以是单个或多个带状阵列。 Multiply that with the number of transfer types supported, and you will see there's a lot of different cases to handle. 将其乘以支持的传输类型的数量,您将看到有很多不同的情况需要处理。 It makes a lot of sense to delegate this to specialized implementations, and avoid having knowledge about all these different types in BufferedImage itself. 将其委托给专门的实现很有意义,并且避免对BufferedImage本身了解所有这些不同类型。

But it doesn't even have to be an array at all. 但这甚至根本不必是数组。 As an example, I have successfully implemented DataBuffer s backed by nio ByteBuffer s and memory mapped files. 例如,我已经成功实现了由nio ByteBuffer和内存映射文件支持的DataBuffer

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

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