refactor(android): Remove useless arguments, fix typo and style
This commit is contained in:
parent
e8c3e1b128
commit
442627bd37
|
@ -26,9 +26,8 @@ import java.util.Date;
|
||||||
*/
|
*/
|
||||||
class ImageResizer {
|
class ImageResizer {
|
||||||
|
|
||||||
private static Bitmap resizeImage(Bitmap image, int maxWidth, int maxHeight, Context context) {
|
private static Bitmap resizeImage(Bitmap image, int maxWidth, int maxHeight) {
|
||||||
Bitmap newImage = null;
|
Bitmap newImage = null;
|
||||||
|
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
return null; // Can't load the image from the given path.
|
return null; // Can't load the image from the given path.
|
||||||
}
|
}
|
||||||
|
@ -84,7 +83,6 @@ class ImageResizer {
|
||||||
return newFile.getAbsolutePath();
|
return newFile.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get {@link File} object for the given Android URI.<br>
|
* Get {@link File} object for the given Android URI.<br>
|
||||||
* Use content resolver to get real path if direct path doesn't return valid file.
|
* Use content resolver to get real path if direct path doesn't return valid file.
|
||||||
|
@ -152,9 +150,6 @@ class ImageResizer {
|
||||||
public static String createResizedImage(Context context, String imagePath, int newWidth,
|
public static String createResizedImage(Context context, String imagePath, int newWidth,
|
||||||
int newHeight, Bitmap.CompressFormat compressFormat,
|
int newHeight, Bitmap.CompressFormat compressFormat,
|
||||||
int quality, int rotation, String outputPath) throws IOException {
|
int quality, int rotation, String outputPath) throws IOException {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Bitmap sourceImage;
|
Bitmap sourceImage;
|
||||||
if (!imagePath.startsWith("content://") && !imagePath.startsWith("file://")) {
|
if (!imagePath.startsWith("content://") && !imagePath.startsWith("file://")) {
|
||||||
sourceImage = BitmapFactory.decodeFile(imagePath);
|
sourceImage = BitmapFactory.decodeFile(imagePath);
|
||||||
|
@ -169,12 +164,12 @@ class ImageResizer {
|
||||||
// Start transformations:
|
// Start transformations:
|
||||||
|
|
||||||
// Scale it first so there are fewer pixels to transform in the rotation
|
// Scale it first so there are fewer pixels to transform in the rotation
|
||||||
Bitmap scaledImage = ImageResizer.resizeImage(sourceImage, newWidth, newHeight, context);
|
Bitmap scaledImage = ImageResizer.resizeImage(sourceImage, newWidth, newHeight);
|
||||||
if (sourceImage != scaledImage) {
|
if (sourceImage != scaledImage) {
|
||||||
sourceImage.recycle();
|
sourceImage.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rotate if neccesary
|
// Rotate if necessary
|
||||||
Bitmap rotatedImage = scaledImage;
|
Bitmap rotatedImage = scaledImage;
|
||||||
if (rotation > 0) {
|
if (rotation > 0) {
|
||||||
int orientation = getOrientation(context, Uri.parse(imagePath));
|
int orientation = getOrientation(context, Uri.parse(imagePath));
|
||||||
|
@ -186,9 +181,10 @@ class ImageResizer {
|
||||||
scaledImage.recycle();
|
scaledImage.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save the resulting image
|
||||||
File path = context.getCacheDir();
|
File path = context.getCacheDir();
|
||||||
if (outputPath != null) {
|
if (outputPath != null) {
|
||||||
path = new File(outputPath);
|
path = new File(outputPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
String resizedImagePath = ImageResizer.saveImage(rotatedImage, path,
|
String resizedImagePath = ImageResizer.saveImage(rotatedImage, path,
|
||||||
|
|
Loading…
Reference in New Issue