Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gl.glPixelStorei(GL20.GL_PACK_ALIGNMENT, 1);
- final Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888);
- ByteBuffer pixels = pixmap.getPixels();
- byte[] bytes = new byte[pixels.remaining()];
- gl.glReadPixels(0, 0, width, height, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixels);
- pixels.get(bytes);
- int bytesSize = bytes.length;
- int[] arrayWitoutAlpha = new int[bytesSize/4];
- int arrayPos = 0;
- for(int i = 0; i < bytesSize; i+=4) {
- arrayWitoutAlpha[arrayPos] = ((bytes[i]&0x0ff) << 16) | ((bytes[i+1]&0x0ff) << 8) | (bytes[i+2]&0x0ff);
- arrayPos++;
- }
- return arrayWitoutAlpha;
- GifEncoder encoder = new GifEncoder(Gdx.files.external("testgif.gif").write(false),
- gifWidth, gifHeight, 1);
- ImageOptions options = new ImageOptions();
- for (int i = 0; i < framesArray.length; i++) { //framesArray - two-dimentional int array with frames
- encoder.addImage(framesArray[i], gifWidth, options);
- }
- encoder.finishEncoding();
- Pixmap pixmap = ...
- int width = pixmap.getWidth(), height = pixmap.getHeight();
- Pixmap flipped = new Pixmap(width, height, pixmap.getFormat());
- for (int x = 0; x < width; ++x)
- for (int y = 0; y < height; ++y)
- flipped.drawPixel(x, y, pixmap.getPixel(x, height - y - 1));
- pixmap.dispose();
- pixmap = flipped;
- int pixel = pixmap.getPixel(x, y); // RGBA
- int r = (pixel >> 24) & 0xFF;
- int g = (pixel >> 16) & 0xFF;
- int b = (pixel >> 8) & 0xFF;
- int a = pixel & 0xFF;
- pixel = (a << 24) + (r << 16) + (g << 8) + b; // ARGB
- Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888);
- ByteBuffer pixels = pixmap.getPixels();
- gl.glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
- frames.add(pixmap);
- // Note that if loopCount is less than 1, then the gif will loop indefinitely
- GifEncoder encoder = new GifEncoder(..., width, height, 0);
- ImageOptions options = new ImageOptions();
- // Frame rate / Time between each frame
- options.setDelay(50, TimeUnit.MILLISECONDS);
- for (Pixmap pixmap : frames) {
- int width = pixmap.getWidth(), height = pixmap.getHeight();
- int[][] pixels = new int[height][width];
- ... flip pixmap on the y-axis ...
- for (int x = 0; x < width; ++x) {
- for (int y = 0; y < height; ++y) {
- int pixel = pixmap.getPixel(x, y);
- ... change pixel format ...
- pixels[y][x] = pixel;
- }
- }
- encoder.addImage(pixels, options);
- }
- encoder.finishEncoding();
- new Thread(new Runnable() {
- @Override
- public void run() {
- ... save gif ...
- }
- }).start();
- for (Pixmap pixmap : frames)
- pixmap.dispose();
- frames.clear();
- PixmapIO.writePNG(fileHandle, pixmap);
- import static com.badlogic.gdx.graphics.GL20.*;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement