当使用机器人GLES20.glReadPixels,通过它返回的数据是不与活preVIEW完全相同 [英] When using GLES20.glReadPixels on android, the data returned by it is not exactly the same with the living preview

查看:2593
本文介绍了当使用机器人GLES20.glReadPixels,通过它返回的数据是不与活preVIEW完全相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这个网页https://github.com/CyberAgent/android-gpuimage做一些实时滤波视频的工作,我用glReadPixels()来获取已经由GPU处理的数据和过滤器已添加,然后创建使用数据恢复和COM preSS它的位图在最后一个JPEG图片。这个过程工作正常,但在 JPEG是不一样的preVIEW,它只是显示了preVIEW的底部,但它的大小是正确的,我一直在寻找这个很长一段时间,但仍然拿不出头绪,所以你们可以给我一些建议,任何建议将大大AP preciated。

I am trying to use Android GPUImage on this page https://github.com/CyberAgent/android-gpuimage to do some real time filtering work on video, and I use glReadPixels() to get the data which has been processed by the GPU and the filter has been added, then I created a bitmap using the data returned and compress it to a jpeg picture at last. The process works fine but the jpeg is not the same as the preview, it just displays the bottom part of the preview, however the size of it is right, I have been searching this for a long time but still get no clue,so can you guys give me some advices,any suggestion will be greatly appreciated.

和我的code,使用glReadPixels是这样的:

And my code that using glReadPixels is like this:

public static Bitmap SavePixels(int x, int y, int w, int h){ 
    int b[]=new int[w*(y+h)];
    int bt[]=new int[w*h];
    IntBuffer ib = IntBuffer.wrap(b);
    ib.position(0);
    GLES20.glReadPixels(0, 0, w, h, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ib);

        for(int i=0, k=0; i<h; i++, k++)
        {//remember, that OpenGL bitmap is incompatible with Android bitmap
         //and so, some correction need.        
             for(int j=0; j<w; j++)
             {
                  int pix=b[i*w+j];
                  int pb=(pix>>16)&0xff;
                  int pr=(pix<<16)&0x00ff0000;
                  int pix1=(pix&0xff00ff00) | pr | pb;
                  bt[(h-k-1)*w+j]=pix1;
             }
        }

        Bitmap sb=Bitmap.createBitmap(bt, w, h, Bitmap.Config.ARGB_8888);
        return sb;
 }

我刚GLES20.glDrawArrays之后调用此函数(GLES20.GL_TRIANGLE_STRIP,0,4),这是在OnDraw函数

I called this function just after the GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4) which is in the onDraw function.

推荐答案

这个问题已经解决了,它的发生是因为glReadPixels读取它与surfaceView连接了preVIEW显示在缓冲区和大小这surfaceView的比宽度和高度PARAMS我在glReadPixels设置好的更大,所以它只是显示preVIEW的部分(从preVIEW的左下角开始)。

This issue has been solved, it happened because the glReadPixels reads the buffer which is connected with the surfaceView that the preview is displayed on, and the size of this surfaceView is bigger than the width and height params I setted in glReadPixels,so it just displayed part of the preview(begins from the left bottom corner of the preview).

这篇关于当使用机器人GLES20.glReadPixels,通过它返回的数据是不与活preVIEW完全相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆