File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
circleimageview/src/main/java/de/hdodenhof/circleimageview Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change 11
11
import android .graphics .Paint ;
12
12
import android .graphics .RectF ;
13
13
import android .graphics .Shader ;
14
+ import android .graphics .drawable .BitmapDrawable ;
14
15
import android .graphics .drawable .Drawable ;
15
16
import android .util .AttributeSet ;
16
17
import android .widget .ImageView ;
@@ -127,11 +128,20 @@ private Bitmap getBitmapFromDrawable(Drawable drawable){
127
128
if (drawable == null ){
128
129
return null ;
129
130
}
130
- Bitmap bitmap = Bitmap .createBitmap (drawable .getIntrinsicWidth (), drawable .getIntrinsicHeight (), Bitmap .Config .ARGB_8888 );
131
- Canvas canvas = new Canvas (bitmap );
132
- drawable .setBounds (0 , 0 , canvas .getWidth (), canvas .getHeight ());
133
- drawable .draw (canvas );
134
- return bitmap ;
131
+
132
+ if (drawable instanceof BitmapDrawable ) {
133
+ return ((BitmapDrawable ) drawable ).getBitmap ();
134
+ }
135
+
136
+ try {
137
+ Bitmap bitmap = Bitmap .createBitmap (drawable .getIntrinsicWidth (), drawable .getIntrinsicHeight (), Bitmap .Config .ARGB_8888 );
138
+ Canvas canvas = new Canvas (bitmap );
139
+ drawable .setBounds (0 , 0 , canvas .getWidth (), canvas .getHeight ());
140
+ drawable .draw (canvas );
141
+ return bitmap ;
142
+ } catch (OutOfMemoryError e ){
143
+ return null ;
144
+ }
135
145
}
136
146
137
147
private void setup (){
You can’t perform that action at this time.
0 commit comments