Skip to content

Instantly share code, notes, and snippets.

@MobiDevelop MobiDevelop/PixmapPut.java Secret
Last active Aug 29, 2015

Embed
What would you like to do?
Bulk puts a byte array into a Pixmap.
Pixmap pix = new Pixmap(1024, 1024, Format.RGBA8888);
byte[] bytes = new byte[1024 * 1024 * 4];
for (int i = 0; i < bytes.length; i += 4) {
bytes[i + 0] = (byte) MathUtils.random(0, 0xFF); // R
bytes[i + 1] = (byte) MathUtils.random(0, 0xFF); // G
bytes[i + 2] = (byte) MathUtils.random(0, 0xFF); // B
bytes[i + 3] = (byte) 0xFF // A
}
// Get the backing ByteBuffer so we can bulk put our byte array
ByteBuffer buf = pix.getPixels();
buf.position(0);
buf.put(bytes);
buf.flip();
// Create our texture from our Pixmap
Texture texture = new Texture(pix);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.