[android] bitmapを指定サイズにトリミング
bitmapを指定サイズにトリミング
private static Bitmap trim(Bitmap image, int maxWidth, int maxHeight) { if (maxHeight > 0 && maxWidth > 0) { int width = image.getWidth(); int height = image.getHeight(); //トリミングする幅、高さ、座標の設定 int startX = (width - maxWidth) /2; int startY = (height - maxHeight)/2; Bitmap result = Bitmap.createBitmap(image, startX, startY, maxWidth, maxHeight, null, true); return result; } else { return image; } }