additional null pointer saftey checks
This commit is contained in:
parent
de0b36fc78
commit
888475d4fe
|
@ -358,11 +358,13 @@ public class FileBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap cropCenterSquare(Uri image, int size) {
|
public Bitmap cropCenterSquare(Uri image, int size) {
|
||||||
|
if (image == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
options.inSampleSize = calcSampleSize(image, size);
|
options.inSampleSize = calcSampleSize(image, size);
|
||||||
InputStream is = mXmppConnectionService.getContentResolver()
|
InputStream is = mXmppConnectionService.getContentResolver().openInputStream(image);
|
||||||
.openInputStream(image);
|
|
||||||
Bitmap input = BitmapFactory.decodeStream(is, null, options);
|
Bitmap input = BitmapFactory.decodeStream(is, null, options);
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -379,12 +381,13 @@ public class FileBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap cropCenter(Uri image, int newHeight, int newWidth) {
|
public Bitmap cropCenter(Uri image, int newHeight, int newWidth) {
|
||||||
|
if (image == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
options.inSampleSize = calcSampleSize(image,
|
options.inSampleSize = calcSampleSize(image,Math.max(newHeight, newWidth));
|
||||||
Math.max(newHeight, newWidth));
|
InputStream is = mXmppConnectionService.getContentResolver().openInputStream(image);
|
||||||
InputStream is = mXmppConnectionService.getContentResolver()
|
|
||||||
.openInputStream(image);
|
|
||||||
Bitmap source = BitmapFactory.decodeStream(is, null, options);
|
Bitmap source = BitmapFactory.decodeStream(is, null, options);
|
||||||
|
|
||||||
int sourceWidth = source.getWidth();
|
int sourceWidth = source.getWidth();
|
||||||
|
@ -397,13 +400,10 @@ public class FileBackend {
|
||||||
float left = (newWidth - scaledWidth) / 2;
|
float left = (newWidth - scaledWidth) / 2;
|
||||||
float top = (newHeight - scaledHeight) / 2;
|
float top = (newHeight - scaledHeight) / 2;
|
||||||
|
|
||||||
RectF targetRect = new RectF(left, top, left + scaledWidth, top
|
RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);
|
||||||
+ scaledHeight);
|
Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, source.getConfig());
|
||||||
Bitmap dest = Bitmap.createBitmap(newWidth, newHeight,
|
|
||||||
source.getConfig());
|
|
||||||
Canvas canvas = new Canvas(dest);
|
Canvas canvas = new Canvas(dest);
|
||||||
canvas.drawBitmap(source, null, targetRect, null);
|
canvas.drawBitmap(source, null, targetRect, null);
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -429,12 +429,10 @@ public class FileBackend {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int calcSampleSize(Uri image, int size)
|
private int calcSampleSize(Uri image, int size) throws FileNotFoundException {
|
||||||
throws FileNotFoundException {
|
|
||||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
options.inJustDecodeBounds = true;
|
options.inJustDecodeBounds = true;
|
||||||
BitmapFactory.decodeStream(mXmppConnectionService.getContentResolver()
|
BitmapFactory.decodeStream(mXmppConnectionService.getContentResolver().openInputStream(image), null, options);
|
||||||
.openInputStream(image), null, options);
|
|
||||||
return calcSampleSize(options, size);
|
return calcSampleSize(options, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue