12
12
import android .graphics .RectF ;
13
13
import android .graphics .Shader ;
14
14
import android .graphics .drawable .BitmapDrawable ;
15
+ import android .graphics .drawable .ColorDrawable ;
15
16
import android .graphics .drawable .Drawable ;
16
17
import android .util .AttributeSet ;
17
18
import android .widget .ImageView ;
@@ -20,6 +21,9 @@ public class CircleImageView extends ImageView {
20
21
21
22
private static final ScaleType SCALE_TYPE = ScaleType .CENTER_CROP ;
22
23
24
+ private static final Bitmap .Config BITMAP_CONFIG = Bitmap .Config .ARGB_8888 ;
25
+ private static final int COLORDRAWABLE_DIMENSION = 1 ;
26
+
23
27
private static final int DEFAULT_BORDER_WIDTH = 0 ;
24
28
private static final int DEFAULT_BORDER_COLOR = Color .BLACK ;
25
29
@@ -134,7 +138,14 @@ private Bitmap getBitmapFromDrawable(Drawable drawable){
134
138
}
135
139
136
140
try {
137
- Bitmap bitmap = Bitmap .createBitmap (drawable .getIntrinsicWidth (), drawable .getIntrinsicHeight (), Bitmap .Config .ARGB_8888 );
141
+ Bitmap bitmap ;
142
+
143
+ if (drawable instanceof ColorDrawable ){
144
+ bitmap = Bitmap .createBitmap (COLORDRAWABLE_DIMENSION , COLORDRAWABLE_DIMENSION , BITMAP_CONFIG );
145
+ } else {
146
+ bitmap = Bitmap .createBitmap (drawable .getIntrinsicWidth (), drawable .getIntrinsicHeight (), BITMAP_CONFIG );
147
+ }
148
+
138
149
Canvas canvas = new Canvas (bitmap );
139
150
drawable .setBounds (0 , 0 , canvas .getWidth (), canvas .getHeight ());
140
151
drawable .draw (canvas );
0 commit comments