cocos2dx lua android glsurfaceview 截图

概述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
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()

总结

以上是内存溢出为你收集整理的cocos2dx lua android glsurfaceview 截图全部内容,希望文章能够帮你解决cocos2dx lua android glsurfaceview 截图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1058248.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存