Android:在屏幕上渲染YUV图像/缓冲区

时间:2012-06-06 08:32:11

标签: android android-imageview yuv android-image

我们的应用程序与显示从另一端收到的实时视频数据有关,我们需要以40毫秒的间隔显示实时视频,

数据将以YUV格式接收,似乎android没有任何内置支持来显示YUV数据,

以下是管理和向屏幕显示数据的代码,

                        // convert the data to RGB 
                            feedProcess.decode(yuvBuffer,
                                    yuvBuffer.length, imgInfo, imgRaw, ref,
                                    webMIndex);


                            currentTime=new Date().getTime();
                            System.out
                            .println("took "+(currentTime-lastTime) +" ms to decode the buffer " );
                            imgQ.add(imgRaw);


In Another thread i will receiving data and converting it into the Bitmap 

            public void run() {
                // TODO Auto-generated method stub
                while(myThreadRun){
                    if(!imgQ.isEmpty()){
                        try{
                        byte[] arry=imgQ.poll();
                        Bitmap b=createImgae(arry, imgInfo[0], imgInfo[1], 1,width,height);
                        myThreadSurfaceView.setBitmap(b);

                        try {
// draw the image 
                            c = myThreadSurfaceHolder.lockCanvas(null);
                            synchronized (myThreadSurfaceHolder) {
                                                                myThreadSurfaceView.onDraw(c);

                            }
                        } finally {
                            if (c != null) {
                                myThreadSurfaceHolder
                                        .unlockCanvasAndPost(c);
                            }
                        }
                        }catch(NoSuchElementException ex){
                        }
                    }
                }
            }

这个整个逻辑需要大约100毫秒来刷新屏幕的新图像,还有其他任何我可以尝试的方法,

解码函数解压缩需要10-15 ms +将YUV转换为RGB(20-30)ms,这是在JNI代码中完成的,

我的理解是,如果可以直接显示YUV数据,那么我们可以节省一些时间,

请告诉你的意见

0 个答案:

没有答案