How to capture image from custom CameraView in Android?

后端 未结 6 678
孤街浪徒
孤街浪徒 2020-11-29 18:36

i need to capture image from required portion of the screen.

capture image from camera.

6条回答
  •  有刺的猬
    2020-11-29 18:54

    I already created like that kind of Camera. What I did is, I covered the other area of the camera with an image, and cut the center part of the image and save it as png file, to make the center transparent.

    You will set background image of your frame(camera preview) with that image. So that it will look like the camera is only that portion that is transparent or the circle.

    I used this tutorial to open,create preview,and take picture from camera device http://developer.android.com/guide/topics/media/camera.html

    in this part(u can see this in the link I provide above)

     private PictureCallback mPicture = new PictureCallback() {
    
     @Override
     public void onPictureTaken(byte[] data, Camera camera) {
       //this is where you crop your image
        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inMutable = true;
        Bitmap bitmap = BitmapFactory
                .decodeByteArray(data, 0, data.length, opt);
    
        bitmap=Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
        Canvas mcanvas=new Canvas(bitmap);
        //do the cropping here, bitmap is the image you will use to crop
    
      }
    
     }
    

    follow this tutorial on how to crop the image to circle Cropping circular area from bitmap in Android

提交回复
热议问题