Capture image using dynamic co-ordinates through the camera

前端 未结 2 1331
半阙折子戏
半阙折子戏 2021-01-06 15:27

I am making a camera based application, where I put a rectangular view over the camera. When I capture an image using new Camera.PictureCallback(), I cropped th

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-06 16:06

    For me, I take a image then crop according to dimension of the selected area of the image..

    public void onPictureTaken(byte[] data, Camera camera) {
    
    
                    Bitmap imageOriginal = BitmapFactory.decodeByteArray(data, 0, data.length, null);
                    int width = imageOriginal.getWidth();
                    int height = imageOriginal.getHeight(); // for width
                    int narrowSize = Math.min(width, height); // for height
                    int differ = (int) Math.abs((imageOriginal.getHeight() - imageOriginal.getWidth()) / 2.0f);  // for dimension
                    width = (width == narrowSize) ? 0 : differ;
                    height = (width == 0) ? differ : 0; 
    
                    Matrix rotationMatrix = new Matrix();
                    rotationMatrix.postRotate(90); // for orientation
    
                    Bitmap imageCropped = Bitmap.createBitmap(imageOriginal, width, height, narrowSize, narrowSize, rotationMatrix, false);
    
    
        }
    

    Capture Image

    Output Image

提交回复
热议问题