2014-01-09 37 views
0

我想用opengl截取我的屏幕截圖。而且我已經通過很多資源,但我無法理解如何以及在何處添加此給定的支持代碼以及如何在我的按鈕中調用它點擊function.Can誰能幫助我與...使用opengl v2截圖android

if(screenshot){      
    int screenshotSize = width * height; 
    ByteBuffer bb = ByteBuffer.allocateDirect(screenshotSize * 4); 
    bb.order(ByteOrder.nativeOrder()); 
    gl.glReadPixels(0, 0, width, height, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, bb); 
    int pixelsBuffer[] = new int[screenshotSize]; 
    bb.asIntBuffer().get(pixelsBuffer); 
    bb = null; 
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); 
    bitmap.setPixels(pixelsBuffer, screenshotSize-width, -width, 0, 0, width, height); 
    pixelsBuffer = null; 

    short sBuffer[] = new short[screenshotSize]; 
    ShortBuffer sb = ShortBuffer.wrap(sBuffer); 
    bitmap.copyPixelsToBuffer(sb); 

    //Making created bitmap (from OpenGL points) compatible with Android bitmap 
    for (int i = 0; i < screenshotSize; ++i) {     
     short v = sBuffer[i]; 
     sBuffer[i] = (short) (((v&0x1f) << 11) | (v&0x7e0) | ((v&0xf800) >> 11)); 
    } 
    sb.rewind(); 
    bitmap.copyPixelsFromBuffer(sb); 
    lastScreenshot = bitmap; 

    screenshot = false; 
} 

回答

0

可以使用覆蓋這樣的:

public static Bitmap overlay(Bitmap bmp1,bmp2 //you can add more you if want) { 
    bmp1 = Bitmapfromopengl; 
    bmp2 = Bitmap2; 

    bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig()); 
    Canvas canvas = new Canvas(bmOverlay); 
    canvas.drawBitmap(bmp1, new Matrix(), null); 
    canvas.drawBitmap(bmp2, 0, 0, null); 
    return bmOverlay; 
}