简体   繁体   English

获取默认的相机预览框

[英]Get default camera preview frames

I have this code to open fefault camera 我有这段代码可以打开fefault相机

Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(camera, CAMERA_REQUEST);

And this for capture the foto 而这是为了捕捉照片

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

            Bitmap bitmap = (Bitmap) Objects.requireNonNull(data.getExtras()).get("data");
            ByteArrayOutputStream stream=new ByteArrayOutputStream();
            assert bitmap != null;
            bitmap.compress(Bitmap.CompressFormat.PNG,100,stream);
            byte[] imageBytes=stream.toByteArray();
            sendReceive.write(String.valueOf(imageBytes.length).getBytes());

            int subArraySize=400;

            for(int i=0;i<imageBytes.length;i+=subArraySize){
                byte[] tempArray;
                tempArray= Arrays.copyOfRange(imageBytes,i,Math.min(imageBytes.length,i+subArraySize));
                sendReceive.write(tempArray);
            }
}

I have a question how i can capture the camera preview frames? 我有一个问题,如何捕捉相机预览框?

You can't do it with an Intent, you have to implement it your way. 您无法使用Intent来实现,而必须以自己的方式实现。 For example, with Camera2 , you have to use a TextureView, CameraCaptureSession, ImageReader, etc. 例如,对于Camera2 ,您必须使用TextureView,CameraCaptureSession,ImageReader等。

You can have a look at this sample 您可以看一下这个样本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM