* Add JmeSystem.writeImageFile() for a platform independent image writing method. Desktop and Android implementations are available. * ScreenshotAppState no longer depends on AWT or Desktop Java, instead it uses JmeSystem.writeImageFile() which will run on Android as well. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9571 75d07b2b-3a1a-0410-a2c5-0572b91ccdca3.0
parent
a3255e4f45
commit
c7186886bc
@ -0,0 +1,42 @@ |
|||||||
|
package com.jme3.util; |
||||||
|
|
||||||
|
import android.graphics.Bitmap; |
||||||
|
import java.nio.ByteBuffer; |
||||||
|
import java.util.logging.Logger; |
||||||
|
|
||||||
|
public final class AndroidScreenshots { |
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(AndroidScreenshots.class.getName()); |
||||||
|
|
||||||
|
/** |
||||||
|
* Convert OpenGL GLES20.GL_RGBA to Bitmap.Config.ARGB_8888 and store result |
||||||
|
* in a Bitmap |
||||||
|
* |
||||||
|
* @param buf ByteBuffer that has the pixel color data from OpenGL |
||||||
|
* @param bitmapImage Bitmap to be used after converting the data |
||||||
|
*/ |
||||||
|
public static void convertScreenShot(ByteBuffer buf, Bitmap bitmapImage) { |
||||||
|
int width = bitmapImage.getWidth(); |
||||||
|
int height = bitmapImage.getHeight(); |
||||||
|
int size = width * height; |
||||||
|
|
||||||
|
// Grab data from ByteBuffer as Int Array to manipulate data and send to image
|
||||||
|
int[] data = new int[size]; |
||||||
|
buf.asIntBuffer().get(data); |
||||||
|
|
||||||
|
// convert from GLES20.GL_RGBA to Bitmap.Config.ARGB_8888
|
||||||
|
// ** need to swap RED and BLUE **
|
||||||
|
for (int idx = 0; idx < data.length; idx++) { |
||||||
|
int initial = data[idx]; |
||||||
|
int pb = (initial >> 16) & 0xff; |
||||||
|
int pr = (initial << 16) & 0x00ff0000; |
||||||
|
int pix1 = (initial & 0xff00ff00) | pr | pb; |
||||||
|
data[idx] = pix1; |
||||||
|
} |
||||||
|
|
||||||
|
// OpenGL and Bitmap have opposite starting points for Y axis (top vs bottom)
|
||||||
|
// Need to write the data in the image from the bottom to the top
|
||||||
|
// Use size-width to indicate start with last row and increment by -width for each row
|
||||||
|
bitmapImage.setPixels(data, size - width, -width, 0, 0, width, height); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue