내 비트 맵 이미지 크기를 최대 640px로 줄이고 싶습니다. 예를 들어, 크기가 1200 x 1200 픽셀 인 비트 맵 이미지가 있습니다. 어떻게하면 640 픽셀로 줄일 수 있습니까? 이 방법비트 맵의 크기를 Android의 특정 픽셀로 줄입니다.
/** getResizedBitmap method is used to Resized the Image according to custom width and height
* @param image
* @param newHeight (new desired height)
* @param newWidth (new desired Width)
* @return image (new resized image)
* */
public static Bitmap getResizedBitmap(Bitmap image, int newHeight, int newWidth) {
int width = image.getWidth();
int height = image.getHeight();
float scaleWidth = ((float) newWidth)/width;
float scaleHeight = ((float) newHeight)/height;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(image, 0, 0, width, height,
matrix, false);
return resizedBitmap;
}
이 스 니펫을 보내 주셔서 감사합니다. 어렵습니다. "if (bitmapRatio> 1)"가 0이 아닌지 확인해야합니다. 높이가 더 크더라도 음수 비율은 없습니다. – ClemM
어디서나이 솔루션을 볼 수 있습니다. 하지만 내 비트 맵을 왜 자르지? 난 단지 상단 부분을 떠난 그것은뿐만 아니라 화면의 오른쪽으로 이동됩니다 ( – Sermilion