@@ -413,7 +413,7 @@ public static Bitmap scale(final Bitmap src,
413
413
final boolean recycle ) {
414
414
if (isEmptyBitmap (src )) return null ;
415
415
Bitmap ret = Bitmap .createScaledBitmap (src , newWidth , newHeight , true );
416
- if (recycle && !src .isRecycled ()) src .recycle ();
416
+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
417
417
return ret ;
418
418
}
419
419
@@ -446,7 +446,7 @@ public static Bitmap scale(final Bitmap src,
446
446
Matrix matrix = new Matrix ();
447
447
matrix .setScale (scaleWidth , scaleHeight );
448
448
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 ();
450
450
return ret ;
451
451
}
452
452
@@ -487,7 +487,7 @@ public static Bitmap clip(final Bitmap src,
487
487
final boolean recycle ) {
488
488
if (isEmptyBitmap (src )) return null ;
489
489
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 ();
491
491
return ret ;
492
492
}
493
493
@@ -558,7 +558,7 @@ public static Bitmap skew(final Bitmap src,
558
558
Matrix matrix = new Matrix ();
559
559
matrix .setSkew (kx , ky , px , py );
560
560
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 ();
562
562
return ret ;
563
563
}
564
564
@@ -598,7 +598,7 @@ public static Bitmap rotate(final Bitmap src,
598
598
Matrix matrix = new Matrix ();
599
599
matrix .setRotate (degrees , px , py );
600
600
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 ();
602
602
return ret ;
603
603
}
604
604
@@ -704,7 +704,7 @@ public static Bitmap toRound(final Bitmap src,
704
704
float radius = center - borderSize / 2f ;
705
705
canvas .drawCircle (width / 2f , height / 2f , radius , paint );
706
706
}
707
- if (recycle && !src .isRecycled ()) src .recycle ();
707
+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
708
708
return ret ;
709
709
}
710
710
@@ -784,7 +784,7 @@ public static Bitmap toRoundCorner(final Bitmap src,
784
784
paint .setStrokeCap (Paint .Cap .ROUND );
785
785
canvas .drawRoundRect (rectF , radius , radius , paint );
786
786
}
787
- if (recycle && !src .isRecycled ()) src .recycle ();
787
+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
788
788
return ret ;
789
789
}
790
790
@@ -935,7 +935,7 @@ public static Bitmap addReflection(final Bitmap src,
935
935
paint .setXfermode (new PorterDuffXfermode (android .graphics .PorterDuff .Mode .DST_IN ));
936
936
canvas .drawRect (0 , srcHeight + REFLECTION_GAP , srcWidth , ret .getHeight (), paint );
937
937
if (!reflectionBitmap .isRecycled ()) reflectionBitmap .recycle ();
938
- if (recycle && !src .isRecycled ()) src .recycle ();
938
+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
939
939
return ret ;
940
940
}
941
941
@@ -987,7 +987,7 @@ public static Bitmap addTextWatermark(final Bitmap src,
987
987
Rect bounds = new Rect ();
988
988
paint .getTextBounds (content , 0 , content .length (), bounds );
989
989
canvas .drawText (content , x , y + textSize , paint );
990
- if (recycle && !src .isRecycled ()) src .recycle ();
990
+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
991
991
return ret ;
992
992
}
993
993
@@ -1033,7 +1033,7 @@ public static Bitmap addImageWatermark(final Bitmap src,
1033
1033
paint .setAlpha (alpha );
1034
1034
canvas .drawBitmap (watermark , x , y , paint );
1035
1035
}
1036
- if (recycle && !src .isRecycled ()) src .recycle ();
1036
+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
1037
1037
return ret ;
1038
1038
}
1039
1039
@@ -1057,7 +1057,7 @@ public static Bitmap toAlpha(final Bitmap src) {
1057
1057
public static Bitmap toAlpha (final Bitmap src , final Boolean recycle ) {
1058
1058
if (isEmptyBitmap (src )) return null ;
1059
1059
Bitmap ret = src .extractAlpha ();
1060
- if (recycle && !src .isRecycled ()) src .recycle ();
1060
+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
1061
1061
return ret ;
1062
1062
}
1063
1063
@@ -1088,7 +1088,7 @@ public static Bitmap toGray(final Bitmap src, final boolean recycle) {
1088
1088
ColorMatrixColorFilter colorMatrixColorFilter = new ColorMatrixColorFilter (colorMatrix );
1089
1089
paint .setColorFilter (colorMatrixColorFilter );
1090
1090
canvas .drawBitmap (src , 0 , 0 , paint );
1091
- if (recycle && !src .isRecycled ()) src .recycle ();
1091
+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
1092
1092
return ret ;
1093
1093
}
1094
1094
@@ -1171,12 +1171,12 @@ public static Bitmap fastBlur(final Bitmap src,
1171
1171
scaleBitmap = stackBlur (scaleBitmap , (int ) radius , recycle );
1172
1172
}
1173
1173
if (scale == 1 || isReturnScale ) {
1174
- if (recycle && !src .isRecycled ()) src .recycle ();
1174
+ if (recycle && !src .isRecycled () && scaleBitmap != src ) src .recycle ();
1175
1175
return scaleBitmap ;
1176
1176
}
1177
1177
Bitmap ret = Bitmap .createScaledBitmap (scaleBitmap , width , height , true );
1178
1178
if (!scaleBitmap .isRecycled ()) scaleBitmap .recycle ();
1179
- if (recycle && !src .isRecycled ()) src .recycle ();
1179
+ if (recycle && !src .isRecycled () && ret != src ) src .recycle ();
1180
1180
return ret ;
1181
1181
}
1182
1182
0 commit comments