简体   繁体   中英

Get default camera preview frames

I have this code to open fefault camera

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. For example, with Camera2 , you have to use a TextureView, CameraCaptureSession, ImageReader, etc.

You can have a look at this sample

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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