ImageBuffer

From Slick2D Wiki
Jump to: navigation, search

Normally you'll load images from files in known formats. However, there are cases where you'd like to be able to generate an image based on a set of data you've created. Some examples are terrain and custom image loading. In Slick you have two options - either you understand the underlying image data classes and build yourself a modified one - or you use the simple ImageBuffer utility class.

An ImageBuffer is set of data that can be converted to a Slick Image at a later point. However, the created image is a copy of the image buffer and hence subsequent changes to the ImageBuffer don't change previously created images.

Using the ImageBuffer is reasonably simple. Create an ImageBuffer with the appropriate size for your desired image - note that this can not be bigger than the texture size supported by your target platform (2048×2048 is a normal, but 512×512 is a safe bet). Next set the pixels in the buffer with setRGBA() as required. Finally convert the buffer into an image by calling getImage(). The returned image will be made up of the buffer's contents converted into an OpenGL texture.

See Also[edit]