我正在使用SurfaceView捕获图像并在public void onPreviewFrame4(byte []数据,相机相机)中获取Yuv Raw预览数据
我必须在onPreviewFrame上执行一些图像预处理,所以我需要将Yuv预览数据转换为RGB数据,而不是图像预处理并返回到Yuv数据.
我使用了两个函数来编码和解码Yuv数据到RGB,如下所示:
public void onPreviewFrame(byte[] data, Camera camera) {
Point cameraResolution = configManager.getCameraResolution();
if (data != null) {
Log.i("DEBUG", "data Not Null");
// Preprocessing
Log.i("DEBUG", "Try For Image Processing");
Camera.Parameters mParameters = camera.getParameters();
Size mSize = mParameters.getPreviewSize();
int mWidth = mSize.width;
int mHeight = mSize.height;
int[] mIntArray = new int[mWidth * mHeight];
// Decode Yuv data to integer array
decodeYUV420SP(mIntArray, data, mWidth, mHeight);
// Converting int mIntArray to Bitmap and
// than image …Run Code Online (Sandbox Code Playgroud) 我正在尝试相机预览
这是我的代码,它不会抛出任何错误,但屏幕仍然是黑色的.有任何想法吗?
this.setContentView(R.layout.camerapreview);
SurfaceView cameraSurface = (SurfaceView)findViewById(R.id.cpPreview);
SurfaceHolder holder = cameraSurface.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
this.camera = Camera.open();
this.camera.setPreviewDisplay(holder);
this.camera.startPreview();
Run Code Online (Sandbox Code Playgroud)
camerapreview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<SurfaceView
android:id="@+id/cpPreview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
</SurfaceView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)