当使用机器人GLES20.glReadPixels,通过它返回的数据是不与活preVIEW完全相同不与、机器人、完全相同、数据

由网友(脚踏两条船你划的真好)分享简介:我想这个网页https://github.com/CyberAgent/android-gpuimage做一些实时滤波视频的工作,我用glReadPixels()来获取已经由GPU处理的数据和过滤器已添加,然后创建使用数据恢复和COM preSS它的位图在最后一个JPEG图片。这个过程工作正常,但在 JPEG是不一样的...

我想这个网页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).

阅读全文

相关推荐

最新文章