Android 显示YUV编码格式

                ByteArrayOutputStream out = new ByteArrayOutputStream();
                String path = "res/drawable/sample.yuv";
                byte buffer[];
                buffer = new byte[1024*1024];

                InputStream is = getClassLoader().getResourceAsStream(path);
                try{
                    is.read(buffer);
                }catch (Exception e)
                {
                    e.printStackTrace();
                }

                YuvImage yuvImage;
                yuvImage = new YuvImage(buffer, ImageFormat.NV21, 640, 480, null);
                yuvImage.compressToJpeg(new Rect(0, 0, 640, 480), 50, out);
                byte[] imageBytes = out.toByteArray();
                Bitmap image = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);

                ImageView iv = (ImageView) findViewById(R.id.iv);
                iv.setImageBitmap(image);

 

posted @ 2013-10-16 16:34  superping  阅读(1166)  评论(0编辑  收藏  举报