@@ -413,7 +413,7 @@ public static Bitmap scale(final Bitmap src,
413413 final boolean recycle ) {
414414 if (isEmptyBitmap (src )) return null ;
415415 Bitmap ret = Bitmap .createScaledBitmap (src , newWidth , newHeight , true );
416- if (recycle && !src .isRecycled ()) src .recycle ();
416+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
417417 return ret ;
418418 }
419419
@@ -446,7 +446,7 @@ public static Bitmap scale(final Bitmap src,
446446 Matrix matrix = new Matrix ();
447447 matrix .setScale (scaleWidth , scaleHeight );
448448 Bitmap ret = Bitmap .createBitmap (src , 0 , 0 , src .getWidth (), src .getHeight (), matrix , true );
449- if (recycle && !src .isRecycled ()) src .recycle ();
449+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
450450 return ret ;
451451 }
452452
@@ -487,7 +487,7 @@ public static Bitmap clip(final Bitmap src,
487487 final boolean recycle ) {
488488 if (isEmptyBitmap (src )) return null ;
489489 Bitmap ret = Bitmap .createBitmap (src , x , y , width , height );
490- if (recycle && !src .isRecycled ()) src .recycle ();
490+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
491491 return ret ;
492492 }
493493
@@ -558,7 +558,7 @@ public static Bitmap skew(final Bitmap src,
558558 Matrix matrix = new Matrix ();
559559 matrix .setSkew (kx , ky , px , py );
560560 Bitmap ret = Bitmap .createBitmap (src , 0 , 0 , src .getWidth (), src .getHeight (), matrix , true );
561- if (recycle && !src .isRecycled ()) src .recycle ();
561+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
562562 return ret ;
563563 }
564564
@@ -598,7 +598,7 @@ public static Bitmap rotate(final Bitmap src,
598598 Matrix matrix = new Matrix ();
599599 matrix .setRotate (degrees , px , py );
600600 Bitmap ret = Bitmap .createBitmap (src , 0 , 0 , src .getWidth (), src .getHeight (), matrix , true );
601- if (recycle && !src .isRecycled ()) src .recycle ();
601+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
602602 return ret ;
603603 }
604604
@@ -704,7 +704,7 @@ public static Bitmap toRound(final Bitmap src,
704704 float radius = center - borderSize / 2f ;
705705 canvas .drawCircle (width / 2f , height / 2f , radius , paint );
706706 }
707- if (recycle && !src .isRecycled ()) src .recycle ();
707+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
708708 return ret ;
709709 }
710710
@@ -784,7 +784,7 @@ public static Bitmap toRoundCorner(final Bitmap src,
784784 paint .setStrokeCap (Paint .Cap .ROUND );
785785 canvas .drawRoundRect (rectF , radius , radius , paint );
786786 }
787- if (recycle && !src .isRecycled ()) src .recycle ();
787+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
788788 return ret ;
789789 }
790790
@@ -935,7 +935,7 @@ public static Bitmap addReflection(final Bitmap src,
935935 paint .setXfermode (new PorterDuffXfermode (android .graphics .PorterDuff .Mode .DST_IN ));
936936 canvas .drawRect (0 , srcHeight + REFLECTION_GAP , srcWidth , ret .getHeight (), paint );
937937 if (!reflectionBitmap .isRecycled ()) reflectionBitmap .recycle ();
938- if (recycle && !src .isRecycled ()) src .recycle ();
938+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
939939 return ret ;
940940 }
941941
@@ -987,7 +987,7 @@ public static Bitmap addTextWatermark(final Bitmap src,
987987 Rect bounds = new Rect ();
988988 paint .getTextBounds (content , 0 , content .length (), bounds );
989989 canvas .drawText (content , x , y + textSize , paint );
990- if (recycle && !src .isRecycled ()) src .recycle ();
990+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
991991 return ret ;
992992 }
993993
@@ -1033,7 +1033,7 @@ public static Bitmap addImageWatermark(final Bitmap src,
10331033 paint .setAlpha (alpha );
10341034 canvas .drawBitmap (watermark , x , y , paint );
10351035 }
1036- if (recycle && !src .isRecycled ()) src .recycle ();
1036+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
10371037 return ret ;
10381038 }
10391039
@@ -1057,7 +1057,7 @@ public static Bitmap toAlpha(final Bitmap src) {
10571057 public static Bitmap toAlpha (final Bitmap src , final Boolean recycle ) {
10581058 if (isEmptyBitmap (src )) return null ;
10591059 Bitmap ret = src .extractAlpha ();
1060- if (recycle && !src .isRecycled ()) src .recycle ();
1060+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
10611061 return ret ;
10621062 }
10631063
@@ -1088,7 +1088,7 @@ public static Bitmap toGray(final Bitmap src, final boolean recycle) {
10881088 ColorMatrixColorFilter colorMatrixColorFilter = new ColorMatrixColorFilter (colorMatrix );
10891089 paint .setColorFilter (colorMatrixColorFilter );
10901090 canvas .drawBitmap (src , 0 , 0 , paint );
1091- if (recycle && !src .isRecycled ()) src .recycle ();
1091+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
10921092 return ret ;
10931093 }
10941094
@@ -1171,12 +1171,12 @@ public static Bitmap fastBlur(final Bitmap src,
11711171 scaleBitmap = stackBlur (scaleBitmap , (int ) radius , recycle );
11721172 }
11731173 if (scale == 1 || isReturnScale ) {
1174- if (recycle && !src .isRecycled ()) src .recycle ();
1174+ if (recycle && !src .isRecycled () && scaleBitmap != src ) src .recycle ();
11751175 return scaleBitmap ;
11761176 }
11771177 Bitmap ret = Bitmap .createScaledBitmap (scaleBitmap , width , height , true );
11781178 if (!scaleBitmap .isRecycled ()) scaleBitmap .recycle ();
1179- if (recycle && !src .isRecycled ()) src .recycle ();
1179+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
11801180 return ret ;
11811181 }
11821182
0 commit comments