Skip to content

Commit

Permalink
Update image export size but it still doesnt work
Browse files Browse the repository at this point in the history
  • Loading branch information
Retera committed Apr 30, 2022
1 parent 61faa91 commit 3a05d3f
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -466,22 +466,24 @@ public void initGL() {
// }
public BufferedImage getBufferedImage() {
try {
final BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
final int imageWidth = (int) (getWidth() * xRatio);
final int imageHeight = (int) (getHeight() * yRatio);
final BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB);
// paintComponent(image.getGraphics(),5);
final Pbuffer buffer = new Pbuffer(getWidth(), getHeight(), new PixelFormat(), null, null);
final Pbuffer buffer = new Pbuffer(imageWidth, imageHeight, new PixelFormat(), null, null);
buffer.makeCurrent();
final ByteBuffer pixels = ByteBuffer.allocateDirect(getWidth() * getHeight() * 4);
final ByteBuffer pixels = ByteBuffer.allocateDirect(imageWidth * imageHeight * 4);
initGL();
paintGL(false);
GL11.glReadPixels(0, 0, getWidth(), getHeight(), GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, pixels);
GL11.glReadPixels(0, 0, imageWidth, imageHeight, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, pixels);
final int[] array = new int[pixels.capacity() / 4];
pixels.asIntBuffer().get(array);
for (int i = 0; i < array.length; i++) {
final int rgba = array[i];
final int a = rgba & 0xFF;
array[i] = rgba >>> 8 | a << 24;
}
image.getRaster().setDataElements(0, 0, getWidth(), getHeight(), array);
image.getRaster().setDataElements(0, 0, imageWidth, imageHeight, array);
buffer.releaseContext();
return createFlipped(image);
} catch (final Exception e) {
Expand Down

0 comments on commit 3a05d3f

Please sign in to comment.