大佬教程收集整理的这篇文章主要介绍了android – 玻璃相机预览显示乱码,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用所有相机默认设置(并且还尝试使用一些不同的图像格式;理想情况下,我可以使用其中一种YUV格式),但显示屏中显示的图像是乱码,如下所示:
布局很简单:
<?xml version="1.0" encoding="utf-8"?> <TextureView xmlns:android="http://scheR_577_11845@as.android.com/apk/res/android" android:id="@+id/scan_preview" android:layout_width="fill_parent" android:layout_height="fill_parent" />
这是活动@L_675_4@:
public class ScanActivity extends Activity { private static final String kTag = ScanActivity.class.getSimplename(); private TextureView mVideoCaptureView = null; private Camera mCamera = null; @Override protected void onCreate(Bundle savedInstanceStatE) { super.onCreate(savedInstanceStatE); setContentView(R.layout.activity_scan); settitle(R.String.title_scan); mVideoCaptureView = (TextureView) findViewById(R.id.scan_preview); mVideoCaptureView.setKeepScreenOn(true); mVideoCaptureView.setSurfaCETextureListener(new VideoCaptureTextureListener()); } @Override protected void onPause() { super.onPause(); stopVideo(); } @Override protected void onResume() { super.onResume(); startVideo(); } private void startVideo() { if (mCamera != null) { mCamera.release(); } mCamera = Camera.open(); if (null != mVideoCaptureView) { try { mCamera.setPreviewTexture(mVideoCaptureView.getSurfaCETexture()); } catch (IOException E) { Log.e(kTag,"Error setTing preview texture",E); return; } } mCamera.startPreview(); } private void stopVideo() { if (null == mCamera) return; try { mCamera.stopPreview(); mCamera.setPreviewDisplay(null); mCamera.setPreviewTexture(null); mCamera.release(); } catch (IOException E) { Log.w(kTag,E); } mCamera = null; } private final class VideoCaptureTextureListener implements TextureView.SurfaCETextureListener { @Override public Boolean onSurfaCETextureDestroyed(SurfaCETexture surfacE) { stopVideo(); return true; } @Override public void onSurfaCETextureAvailable(SurfaCETexture surface,int width,int height) { startVideo(); } @Override public void onSurfaCETextureSizeChanged(SurfaCETexture surface,int height) { } @Override public void onSurfaCETextureupdated(SurfaCETexture surfacE) { } } }
长期:
Camera.Parameters params = camera.getParameters(); params.setPreviewFpsRange(30000,30000); camera.setParameters(params);
Shorterm(测试):
android:layout_margin="1dp"
例如:
<LinearLayout xmlns:android="http://scheR_577_11845@as.android.com/apk/res/android" xmlns:tools="http://scheR_577_11845@as.android.com/tools" android:layout_width="match_parent" android:layout_margin="1dp" android:layout_height="match_parent" > <org.opencv.android.JavaCameraView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tutorial2_activity_surface_view" /> </LinearLayout>
以上是大佬教程为你收集整理的android – 玻璃相机预览显示乱码全部内容,希望文章能够帮你解决android – 玻璃相机预览显示乱码所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。