Skip to content

Commit

Permalink
Prevent from null pointer exception
Browse files Browse the repository at this point in the history
Which was caused by image loader.
  • Loading branch information
mrjohannchang committed Dec 22, 2014
1 parent 25fd1dd commit 894c958
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,14 @@ else if (drawable instanceof BitmapDrawable) // Use the getBitmap() method in
return ((BitmapDrawable) drawable).getBitmap();

// Create Bitmap object out of the drawable
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Bitmap bitmap = null;

int intrinsicWidth = drawable.getIntrinsicWidth();
int intrinsicHeight = drawable.getIntrinsicHeight();

if (!(intrinsicWidth > 0 && intrinsicHeight > 0)) return bitmap;

bitmap = Bitmap.createBitmap(intrinsicWidth, intrinsicHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
Expand All @@ -390,6 +397,7 @@ else if (drawable instanceof BitmapDrawable) // Use the getBitmap() method in
* the Circle upon drawing.
*/
public void refreshBitmapShader() {
if (image == null) return;
shader = new BitmapShader(Bitmap.createScaledBitmap(image, canvasSize, canvasSize, false), Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
}

Expand All @@ -400,4 +408,4 @@ public void refreshBitmapShader() {
public boolean isSelected() {
return this.isSelected;
}
}
}

0 comments on commit 894c958

Please sign in to comment.