问题
I have a SurfaceView on screen and i want to know its starting x,y position on screen and also its width and height so as i can crop the full screen image only to the SurfaceView size part means whatever fits in that bounds and the rest of the part to be chopped off. The code I am trying is:
Bitmap bitmap = BitmapFactory.decodeByteArray(mCameraData, 0, mCameraData.length);
int[] location = new int[2];
mCameraPreview.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
Bitmap resizedbitmap1=Bitmap.createBitmap(bitmap, x,y,mCameraPreview.getWidth(), mCameraPreview.getHeight());
mCameraImage.setImageBitmap(resizedbitmap1);
But it is taking some left part of the screen from the image. Please help.
Edit:
private void setupImageDisplay() {
Bitmap bitmap = BitmapFactory.decodeByteArray(mCameraData, 0, mCameraData.length);
int[] location = new int[2];
mCameraPreview.getLocationOnScreen(location); //view
int x = location[0];
int y = location[1];
Bitmap resizedbitmap1=Bitmap.createBitmap(bitmap, x,y,mCameraPreview.getWidth(), mCameraPreview.getHeight());
mCameraImage.setImageBitmap(resizedbitmap1);
mCamera.stopPreview();
mCameraPreview.setVisibility(View.INVISIBLE);
s1.setVisibility(View.INVISIBLE);
v1.setVisibility(View.INVISIBLE);
mCameraImage.setVisibility(View.VISIBLE);
mCaptureImageButton.setText(R.string.recapture_image);
mCaptureImageButton.setOnClickListener(mRecaptureImageButtonClickListener);
}
But my SurfaceView doesn't cover the full screen.
New Edit:
Here's the screen to demonstrate what i want:
I want the part of the image only in blue rectangle. So please help.
来源:https://stackoverflow.com/questions/61732571/how-to-crop-a-bitmap-as-of-same-size-of-a-rectangular-imageview