PreviewCallback中的data資料畫圖出現了花屏現象

來源:互聯網
上載者:User

Camera.PreviewCallback

public void onPreviewFrame(byte[] data, Camera camera)

之前由於Camera的preview format只支援:

PixelFormat.YCbCr_420_SP ---> instead ImageFormat.NV21這種圖片格式(使用

int format = parameters.getPreviewFormat();Log.d(TAG, "preview format:"+format);

查看)

使得BitmapFactory.decodeByteArray一直解碼不出圖片,網上找了半天,後來終於找到了轉碼的方法,sdk2.2及以上的系統提供了轉換介面,yuvimage類的compressToJpeg函數。

使用了它以後,自拍preview的資料可以畫在canvas上了,而且和surfaceView裡預覽的網路攝影機畫面一致,但是把它換成了後置網路攝影機,canvas畫圖的花屏圖片,出現了花屏現象一般就是使用了preview不支援的size,我跟蹤代碼,看了看代碼:

List<Size> pszize = parameters.getSupportedPreviewSizes();        if (null != pszize && 0 < pszize.size()) {                int height[] = new int[pszize.size()];// 聲明一個數組                Map<Integer, Integer> map = new HashMap<Integer, Integer>();                for (int i = 0; i < pszize.size(); i++) {                                    Size size = (Size) pszize.get(i);                    int sizeheight = size.height;                    int sizewidth = size.width;                    height[i] = sizeheight;                    map.put(sizeheight, sizewidth);//                    Log.d(TAG, "size.width:"+sizewidth+"\tsize.height:"+sizeheight);                }                Arrays.sort(height);             // 設定//                parameters.setPictureSize(map.get(height[0]),height[0]);    parameters.setPreviewSize(map.get(height[1]),height[1]);          }

我是使用網路攝影機支援的preview size啊,就這樣找不出原因。

後來過了兩天,我從網上閑逛,看了別人的代碼,和這個無關,突發奇想:

@Overridepublic void onPreviewFrame(byte[] data, Camera camera) {// TODO Auto-generated method stub    //在視訊交談中,這裡傳送本地frame資料給remote端//Log.d(TAG, "camera:"+camera);int width = camera.getParameters().getPreviewSize().width;int height = camera.getParameters().getPreviewSize().height;...............................}

遠端視頻資料也就正確的畫出來了。拖了幾天的問題,╮(╯▽╰)╭。有哪位大神知道原因,請指導哈

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.