11/*
2- * Copyright 2009 Pader-Sync Ltd. & Co. KG. All Rights Reserved.
2+ * Copyright 2009 Pader-Sync Ltd. & Co. KG. All Rights Reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
@@ -144,18 +144,18 @@ public void drawImage(Object img, int x, int y) {
144144 }
145145
146146 public void drawShadow (Object image , int x , int y , int offsetX , int offsetY , int blurRadius , int spreadRadius , int color , float opacity ) {
147- if (image == null ) return ;
147+ if (image == null || canvas == null ) {
148+ return ;
149+ }
148150 Bitmap bmp = (Bitmap )image ;
149151 float bmpW = bmp .getWidth ();
150152 float bmpH = bmp .getHeight ();
151- if (bmpW == 0 || bmpH == 0 ) return ;
152-
153-
153+ if (bmpW == 0 || bmpH == 0 ) {
154+ return ;
155+ }
154156
155157 Bitmap scaledBmp = Bitmap .createScaledBitmap (bmp , bmp .getWidth () + 2 * spreadRadius , bmp .getHeight () + 2 * spreadRadius , false );
156-
157158 Paint alphaPaint = new Paint ();
158-
159159 alphaPaint .setMaskFilter (new BlurMaskFilter (blurRadius , BlurMaskFilter .Blur .NORMAL ));
160160 int [] offsetXY = new int [2 ];
161161 Bitmap bmAlpha = scaledBmp .extractAlpha (alphaPaint , offsetXY );
@@ -164,13 +164,11 @@ public void drawShadow(Object image, int x, int y, int offsetX, int offsetY, int
164164 applyTransform ();
165165 Paint shadowPaint = new Paint ();
166166 int alpha = (int )Math .floor (opacity * 255 );
167- shadowPaint .setColor ((0xff000000 | color ));
168- shadowPaint .setAlpha ((int )Math .floor (opacity * 255 ));
169-
167+ shadowPaint .setColor (0xff000000 | color );
168+ shadowPaint .setAlpha (alpha );
170169 canvas .drawBitmap (bmAlpha , x + offsetXY [0 ] - spreadRadius + offsetX , y + offsetXY [1 ] - spreadRadius + offsetY , shadowPaint );
171170 bmAlpha .recycle ();
172171
173-
174172 unapplyTransform ();
175173 canvas .restore ();
176174 }
0 commit comments