|
@@ -60,6 +60,32 @@ public final class ImageUtil {
|
|
|
return out.toByteArray();
|
|
return out.toByteArray();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存图片并压缩指定倍数
|
|
|
|
|
+ * @param bitmap
|
|
|
|
|
+ * @param file
|
|
|
|
|
+ * @param multi
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public static boolean saveBitmapFile(Bitmap bitmap, File file, int multi) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Bitmap compressedBitmap = bitmap;
|
|
|
|
|
+ if (multi > 1) {
|
|
|
|
|
+ int targetWidth = bitmap.getWidth()/multi;
|
|
|
|
|
+ int targetHeight = bitmap.getHeight()/multi;
|
|
|
|
|
+ compressedBitmap = Bitmap.createScaledBitmap(bitmap, targetWidth, targetHeight, true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
|
|
|
|
|
+ compressedBitmap.compress(Bitmap.CompressFormat.JPEG, 98, bos);
|
|
|
|
|
+ bos.flush();
|
|
|
|
|
+ bos.close();
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
public static boolean saveBitmapFile(Bitmap bitmap, File file){
|
|
public static boolean saveBitmapFile(Bitmap bitmap, File file){
|
|
|
try {
|
|
try {
|
|
@@ -74,6 +100,21 @@ public final class ImageUtil {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public static Bitmap getResizedBitmap(Bitmap image, int maxSize) {
|
|
|
|
|
+ int width = image.getWidth();
|
|
|
|
|
+ int height = image.getHeight();
|
|
|
|
|
+
|
|
|
|
|
+ float bitmapRatio = (float)width / (float) height;
|
|
|
|
|
+ if (bitmapRatio > 1) {
|
|
|
|
|
+ width = maxSize;
|
|
|
|
|
+ height = (int) (width / bitmapRatio);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ height = maxSize;
|
|
|
|
|
+ width = (int) (height * bitmapRatio);
|
|
|
|
|
+ }
|
|
|
|
|
+ return Bitmap.createScaledBitmap(image, width, height, true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 顺时针旋转90度
|
|
* 顺时针旋转90度
|
|
|
* @return
|
|
* @return
|