private int[] copyDataToBitmap(float viewPortHeight,Rect rect) {
int rectWidth = rect.width();
int rectHeight = rect.height();
IntBuffer intBuffer = IntBuffer.allocate(rectWidth * rectHeight);
GLES30.glReadPixels((int) rect.left, (int) (viewPortHeight - rect.bottom), rectWidth, rectHeight,
GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, intBuffer);
int[] array = intBuffer.array();
IntBuffer invertBuffer = IntBuffer.allocate(array.length);
for (int i = 0; i < rectHeight; i++) {
invertBuffer.put(array,(rectHeight-i-1) * rectWidth,rectWidth);
}
return invertBuffer.array();
}
private void debug_cache(){
Bitmap bitmap_main = Bitmap.createBitmap((int)visibleWidth,(int)visibleHeight, Bitmap.Config.ARGB_8888);
bitmap_main.eraseColor(Color.RED);
int[] bitmapDataTest = copyDataToBitmap((int)visibleHeight,new Rect(0,0,(int)visibleWidth,(int)visibleHeight));
bitmap_main.setPixels(bitmapDataTest, 0, (int)visibleWidth, 0, 0, (int)visibleWidth,(int)visibleHeight);
long timeNow=System.nanoTime();
saveBitmapAsPng(bitmap_main,""+timeNow+"drawPredictPoint"+"_start.png");
}
public static void mkdir(String dir) {
File f = new File(dir);
if (!f.exists())
f.mkdirs();
}
public static void saveBitmapAsPng(Bitmap bmp, String name) {
try {
String dir="/storage/emulated/0/Android/data/com.sunia.PenEngine/files/Documents/log_img/";
mkdir(dir);
File f = new File(dir+name);
FileOutputStream out = new FileOutputStream(f);
bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
|