Skip to content
Advertisement

BufferedImage getTile(): what is it, how does it differ from getSubimage()

What is BufferedImage getTile()? I see that is returns a Raster object. Is this another form of an image or graphical object? If so, what advantages / disadvantages are there to using getTile() vs using getSubImage()?

Advertisement

Answer

The BufferedImage.getTile(int, int) method is inherited from the RenderedImage interface, and allows you to get a specific tile to work on. All tiles in an image have equal, fixed, width/height. Each tile is typically one contiguous block of memory. In contrast, getSubImage() allows you to get an arbitrary region from the image, regardless of the backing memory. So the methods are not really interchangeable. They are similar in the way they both return “live” views of the full image.

For a BufferedImage instance, however, the getTile() method is not very useful, as a BufferedImage is implemented as a single tile (ie. anything other than bufferedImage.getTile(0, 0) will throw an IndexOutOfBoundsException). If you know you are operating on a BufferedImage, the getRaster() method is a better option and will do exactly the same.

Other implementations of RenderedImage, however, might contain several tiles, and you would use the various tile-related methods to find the number of tiles in each dimension, the tile sizes etc.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement