imageview에서 이미지의 일부만 보여주고 싶습니다. 다음 이미지를 참조하십시오. android - 이미지의 일부분을 잘라내어 이미지 뷰에 표시하는 방법
동일한 예는 이미지가있는 모든 소식을 볼 수있는 google + 앱에서 찾을 수 있습니다.
모든 링크는 코드 도움이 될 것입니다. 감사
imageview에서 이미지의 일부만 보여주고 싶습니다. 다음 이미지를 참조하십시오. android - 이미지의 일부분을 잘라내어 이미지 뷰에 표시하는 방법
동일한 예는 이미지가있는 모든 소식을 볼 수있는 google + 앱에서 찾을 수 있습니다.
모든 링크는 코드 도움이 될 것입니다. 감사
사용 누군가가
Y이 논리로 다음 PARAMS을 바닥
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, x, y,
width, height, matrix, true);
에서 이미지를 잘라 대체하기 위해 찾고 있다면
int width = bitmapOrg.width();
int height = bitmapOrg.height();
int newWidth = 200;
int newHeight = 200;
// calculate the scale - in this case = 0.4f
float scaleWidth = ((float) newWidth)/width;
float scaleHeight = ((float) newHeight)/height;
// createa matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
width, height, matrix, true);
// make a Drawable from Bitmap to allow to set the BitMap
// to the ImageView, ImageButton or what ever
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
ImageView imageView = new ImageView(this);
// set the Drawable on the ImageView
imageView.setImageDrawable(bmd);
// Set some constants
private static final Bitmap SOURCE_BITMAP = BitmapFactory.decodeFile(....); // Get the source Bitmap using your favorite method :-)
private static final int START_X = 10;
private static final int START_Y = 15;
private static final int WIDTH_PX = 100;
private static final int HEIGHT_PX = 100;
// Crop bitmap
Bitmap newBitmap = Bitmap.createBitmap(SOURCE_BITMAP, START_X, START_Y, WIDTH_PX, HEIGHT_PX, null, false);
// Assign new bitmap to ImageView
ImageView image = (ImageView)findViewById(R.id.image_view);
image.setImageBitmap(newBitmap);
나는 이것을 시도했지만 나는 기울어진다. 장치 화면 크기에 따라 새 이미지 너비를 설정하십시오. deepika 응답에 대한 의견 1 번 참조 – rohit
디스플레이 표시 = ((WindowManager) getSystemService (Context.WINDOW_SERVICE)). getDefaultDisplay(); int screenWidth = display.getWidth(); –
이 코드 : (bitmapOrg .getHeight() - 1) - (질문에있는 빨간색 상자의 높이)
높이 : (질문에 빨간색 상자 선물의 높이)
사용하면 다음과 같은 예외를 피할 수있는이 방법 (대한 그에 따라 수정해야 x)를
IllegalArgumentException: x + width must be <= bitmap.width() in android
IllegalArgumentException: y + width must be <= bitmap.height() in android
에 newWidth가 동일하게 설정하는 방법 장치 너비에 따라 이미지의 크기가 조정됩니까? – rohit
int newWidth = getWindowManager(). getDefaultDisplay(). getWidth(); – Deepika
btw 한 가지 문제 - 스트레칭 이미지입니다. 스트레칭 이미지를 원하지 않습니다. 예를 들어 문제의 예제에 표시된대로 이미지의 일부를 자르고 싶습니다. 더 일반적으로 잘라내기를 원합니다 :) – rohit