android视频流花屏onPreviewFrame不受控制!!!!!!!!

try {
     mycamera = Camera.open();
     mycamera.startPreview();
     mParameters = mycamera.getParameters();//得到摄像参数
     ListSupportedPreviewSizes = mParameters.getSupportedPreviewSizes();
 
     for (Size size : SupportedPreviewSizes) 
     {
         if(size.width * size.height < 300000)
         {
              continue ;
         }
 
         if (optimalSize == null) 
         {
              optimalSize = size ;
              continue ;
         }
 
         if (size.width < optimalSize.width)
         {
              optimalSize = size ;
         }
     }
 
     Log.e("UI", "width = " + optimalSize.width + " height = " + optimalSize.height);
 
     if (optimalSize != null)
         mParameters.setPreviewSize(optimalSize.width, optimalSize.height);
 
     mycamera.setParameters(mParameters);
 
     mycamera.setPreviewDisplay(mSurfaceview.getHolder());
 
} catch (IOException e) {}
 


以上代码为设置视频流的size,可是屏幕上花屏

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

里data.length明显和width * hight * 3 / 2得到的length不等

到底是什么原因呢?


try {
	mycamera = Camera.open();
	mycamera.startPreview();

	mParameters = mycamera.getParameters();//得到摄像参数
	List SupportedPreviewSizes = mParameters.getSupportedPreviewSizes();
	optimalSize = mParameters.getPreviewSize() ;

	for (Size size : SupportedPreviewSizes) 
	{
		if(size.width * size.height < 300000)
		{
			continue ;
		}

		if(optimalSize.height * size.width != optimalSize.width * size.height)
		{
			continue ;
		}

		if (size.width < optimalSize.width)
		{
			optimalSize = size ;
		}
	}

	Log.e("UI", "width = " + optimalSize.width + " height = " + optimalSize.height);

	if (optimalSize != null)
		mParameters.setPreviewSize(optimalSize.width, optimalSize.height);

	mycamera.setParameters(mParameters);

	mycamera.setPreviewDisplay(mSurfaceview.getHolder());

} catch (IOException e) {}

这是我改动的代码 只是增加了
if(optimalSize.height * size.width != optimalSize.width * size.height)

执行后就不花屏了!!!!!!!

原来视频流的帧要保持宽高比例!!!



你可能感兴趣的:(android视频流花屏onPreviewFrame不受控制!!!!!!!!)