加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2dx lua android glsurfaceview 截图

发布时间:2020-12-14 21:20:40 所属栏目:百科 来源:网络整理
导读:private Bitmap createBitmapFromGLSurface(int x,int y,int w,int h,GL10 gl) throws OutOfMemoryError { int bitmapBuffer[] = new int[w * h]; int bitmapSource[] = new int[w * h]; IntBuffer intBuffer = IntBuffer.wrap(bitmapBuffer); intBuffer.pos
private Bitmap createBitmapFromGLSurface(int x,int y,int w,int h,GL10 gl) throws OutOfMemoryError {
    int bitmapBuffer[] = new int[w * h];
    int bitmapSource[] = new int[w * h];
    IntBuffer intBuffer = IntBuffer.wrap(bitmapBuffer);
    intBuffer.position(0);

    try {
        gl.glReadPixels(x,y,w,h,GL10.GL_RGBA,GL10.GL_UNSIGNED_BYTE,intBuffer);
        int offset1,offset2;

        for (int i = 0; i < h; i++) {
            offset1 = i * w;
            offset2 = (h - i - 1) * w;
            for (int j = 0; j < w; j++) {
                int texturePixel = bitmapBuffer[offset1 + j];
                int blue = (texturePixel >> 16) & 0xff;
                int red = (texturePixel << 16) & 0x00ff0000;
                int pixel = (texturePixel & 0xff00ff00) | red | blue;
                bitmapSource[offset2 + j] = pixel;
            }
        }
    } catch (GLException e) {
        return null;
    }

    return Bitmap.createBitmap(bitmapSource,Bitmap.Config.ARGB_8888);
}

public String grabScreenShots(final String fileName) {
    String filePath = fileName;

    GL10 g1 = glSurView.getGLHandler();
    int w = glSurView.getWidth();
    int h = glSurView.getHeight();
    Log.e("w",String.valueOf(w));
    Log.e("h",String.valueOf(h));
    Bitmap bmp = createBitmapFromGLSurface(0,g1);
    File file = new File(filePath);
    try {
        file.createNewFile();
        FileOutputStream fos = new FileOutputStream(file);
        bmp.compress(CompressFormat.JPEG,100,fos);

// Toast.makeText(getApplicationContext(),“Image Saved”,0).show();
// Log.i(“Menu Save Button”,“Image saved as JPEG”);
} catch (Exception e) {
e.printStackTrace();
}
return filePath;
}

Render ondrawFrame中get到GL10对象,吐出来喂食 glSufaceview可以get到width、height createBitmapFromGLSurface()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读