Working in a BufferedImage's int[] pixels array

穿精又带淫゛_ 提交于 2019-12-03 15:25:20

The whole point of getData() giving you access to the backing int array is precisely for this optimization, so the benefits most likely outweigh the drawbacks.

The drawbacks depend on how you're using the buffered image. If you're drawing it to the screen while you're editing it, you may encounter some artifacts on the screen (like pixels not colored in time), in which case you should consider double buffering (which does involve copying over the entire image for every refresh).

Not sure if this is relevant for your question, but you will run into problems when the BufferedImage was created using the method getSubimage(int x, int y, int w, int h).

Returns a subimage defined by a specified rectangular region. The returned BufferedImage shares the same data array as the original image.

The methods getTileGridXOffset() and getTileGridYOffset() return the offset then despite being described as

Returns the x offset of the tile grid relative to the origin, For example, the x coordinate of the location of tile (0, 0). This is always zero.

but because you can't (as far as I know) access the scanlineStride field of the raster you won't be able to get the correct index for the array.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!