@@ -82,7 +82,9 @@ public static byte[] bitmap2Bytes(final Bitmap bitmap, final CompressFormat form
8282 * @return bitmap
8383 */
8484 public static Bitmap bytes2Bitmap (final byte [] bytes ) {
85- return (bytes == null || bytes .length == 0 ) ? null : BitmapFactory .decodeByteArray (bytes , 0 , bytes .length );
85+ return (bytes == null || bytes .length == 0 )
86+ ? null
87+ : BitmapFactory .decodeByteArray (bytes , 0 , bytes .length );
8688 }
8789
8890 /**
@@ -101,10 +103,15 @@ public static Bitmap drawable2Bitmap(final Drawable drawable) {
101103 Bitmap bitmap ;
102104 if (drawable .getIntrinsicWidth () <= 0 || drawable .getIntrinsicHeight () <= 0 ) {
103105 bitmap = Bitmap .createBitmap (1 , 1 ,
104- drawable .getOpacity () != PixelFormat .OPAQUE ? Bitmap .Config .ARGB_8888 : Bitmap .Config .RGB_565 );
106+ drawable .getOpacity () != PixelFormat .OPAQUE
107+ ? Bitmap .Config .ARGB_8888
108+ : Bitmap .Config .RGB_565 );
105109 } else {
106- bitmap = Bitmap .createBitmap (drawable .getIntrinsicWidth (), drawable .getIntrinsicHeight (),
107- drawable .getOpacity () != PixelFormat .OPAQUE ? Bitmap .Config .ARGB_8888 : Bitmap .Config .RGB_565 );
110+ bitmap = Bitmap .createBitmap (drawable .getIntrinsicWidth (),
111+ drawable .getIntrinsicHeight (),
112+ drawable .getOpacity () != PixelFormat .OPAQUE
113+ ? Bitmap .Config .ARGB_8888
114+ : Bitmap .Config .RGB_565 );
108115 }
109116 Canvas canvas = new Canvas (bitmap );
110117 drawable .setBounds (0 , 0 , canvas .getWidth (), canvas .getHeight ());
@@ -151,7 +158,9 @@ public static Drawable bytes2Drawable(final byte[] bytes) {
151158 */
152159 public static Bitmap view2Bitmap (final View view ) {
153160 if (view == null ) return null ;
154- Bitmap ret = Bitmap .createBitmap (view .getWidth (), view .getHeight (), Bitmap .Config .ARGB_8888 );
161+ Bitmap ret = Bitmap .createBitmap (view .getWidth (),
162+ view .getHeight (),
163+ Bitmap .Config .ARGB_8888 );
155164 Canvas canvas = new Canvas (ret );
156165 Drawable bgDrawable = view .getBackground ();
157166 if (bgDrawable != null ) {
@@ -267,7 +276,10 @@ public static Bitmap getBitmap(final byte[] data, final int offset) {
267276 * @param maxHeight 最大高度
268277 * @return bitmap
269278 */
270- public static Bitmap getBitmap (final byte [] data , final int offset , final int maxWidth , final int maxHeight ) {
279+ public static Bitmap getBitmap (final byte [] data ,
280+ final int offset ,
281+ final int maxWidth ,
282+ final int maxHeight ) {
271283 if (data .length == 0 ) return null ;
272284 BitmapFactory .Options options = new BitmapFactory .Options ();
273285 options .inJustDecodeBounds = true ;
@@ -286,7 +298,9 @@ public static Bitmap getBitmap(final byte[] data, final int offset, final int ma
286298 public static Bitmap getBitmap (@ DrawableRes final int resId ) {
287299 Drawable drawable = ContextCompat .getDrawable (Utils .getApp (), resId );
288300 Canvas canvas = new Canvas ();
289- Bitmap bitmap = Bitmap .createBitmap (drawable .getIntrinsicWidth (), drawable .getIntrinsicHeight (), Bitmap .Config .ARGB_8888 );
301+ Bitmap bitmap = Bitmap .createBitmap (drawable .getIntrinsicWidth (),
302+ drawable .getIntrinsicHeight (),
303+ Bitmap .Config .ARGB_8888 );
290304 canvas .setBitmap (bitmap );
291305 drawable .setBounds (0 , 0 , drawable .getIntrinsicWidth (), drawable .getIntrinsicHeight ());
292306 drawable .draw (canvas );
@@ -301,7 +315,9 @@ public static Bitmap getBitmap(@DrawableRes final int resId) {
301315 * @param maxHeight 最大高度
302316 * @return bitmap
303317 */
304- public static Bitmap getBitmap (@ DrawableRes final int resId , final int maxWidth , final int maxHeight ) {
318+ public static Bitmap getBitmap (@ DrawableRes final int resId ,
319+ final int maxWidth ,
320+ final int maxHeight ) {
305321 BitmapFactory .Options options = new BitmapFactory .Options ();
306322 final Resources resources = Utils .getApp ().getResources ();
307323 options .inJustDecodeBounds = true ;
@@ -330,7 +346,9 @@ public static Bitmap getBitmap(final FileDescriptor fd) {
330346 * @param maxHeight 最大高度
331347 * @return bitmap
332348 */
333- public static Bitmap getBitmap (final FileDescriptor fd , final int maxWidth , final int maxHeight ) {
349+ public static Bitmap getBitmap (final FileDescriptor fd ,
350+ final int maxWidth ,
351+ final int maxHeight ) {
334352 if (fd == null ) return null ;
335353 BitmapFactory .Options options = new BitmapFactory .Options ();
336354 options .inJustDecodeBounds = true ;
@@ -361,7 +379,10 @@ public static Bitmap scale(final Bitmap src, final int newWidth, final int newHe
361379 * @param recycle 是否回收
362380 * @return 缩放后的图片
363381 */
364- public static Bitmap scale (final Bitmap src , final int newWidth , final int newHeight , final boolean recycle ) {
382+ public static Bitmap scale (final Bitmap src ,
383+ final int newWidth ,
384+ final int newHeight ,
385+ final boolean recycle ) {
365386 if (isEmptyBitmap (src )) return null ;
366387 Bitmap ret = Bitmap .createScaledBitmap (src , newWidth , newHeight , true );
367388 if (recycle && !src .isRecycled ()) src .recycle ();
@@ -389,7 +410,10 @@ public static Bitmap scale(final Bitmap src, final float scaleWidth, final float
389410 * @param recycle 是否回收
390411 * @return 缩放后的图片
391412 */
392- public static Bitmap scale (final Bitmap src , final float scaleWidth , final float scaleHeight , final boolean recycle ) {
413+ public static Bitmap scale (final Bitmap src ,
414+ final float scaleWidth ,
415+ final float scaleHeight ,
416+ final boolean recycle ) {
393417 if (isEmptyBitmap (src )) return null ;
394418 Matrix matrix = new Matrix ();
395419 matrix .setScale (scaleWidth , scaleHeight );
@@ -408,7 +432,11 @@ public static Bitmap scale(final Bitmap src, final float scaleWidth, final float
408432 * @param height 裁剪高度
409433 * @return 裁剪后的图片
410434 */
411- public static Bitmap clip (final Bitmap src , final int x , final int y , final int width , final int height ) {
435+ public static Bitmap clip (final Bitmap src ,
436+ final int x ,
437+ final int y ,
438+ final int width ,
439+ final int height ) {
412440 return clip (src , x , y , width , height , false );
413441 }
414442
@@ -423,7 +451,12 @@ public static Bitmap clip(final Bitmap src, final int x, final int y, final int
423451 * @param recycle 是否回收
424452 * @return 裁剪后的图片
425453 */
426- public static Bitmap clip (final Bitmap src , final int x , final int y , final int width , final int height , final boolean recycle ) {
454+ public static Bitmap clip (final Bitmap src ,
455+ final int x ,
456+ final int y ,
457+ final int width ,
458+ final int height ,
459+ final boolean recycle ) {
427460 if (isEmptyBitmap (src )) return null ;
428461 Bitmap ret = Bitmap .createBitmap (src , x , y , width , height );
429462 if (recycle && !src .isRecycled ()) src .recycle ();
@@ -451,7 +484,10 @@ public static Bitmap skew(final Bitmap src, final float kx, final float ky) {
451484 * @param recycle 是否回收
452485 * @return 倾斜后的图片
453486 */
454- public static Bitmap skew (final Bitmap src , final float kx , final float ky , final boolean recycle ) {
487+ public static Bitmap skew (final Bitmap src ,
488+ final float kx ,
489+ final float ky ,
490+ final boolean recycle ) {
455491 return skew (src , kx , ky , 0 , 0 , recycle );
456492 }
457493
@@ -465,7 +501,11 @@ public static Bitmap skew(final Bitmap src, final float kx, final float ky, fina
465501 * @param py 平移因子 y
466502 * @return 倾斜后的图片
467503 */
468- public static Bitmap skew (final Bitmap src , final float kx , final float ky , final float px , final float py ) {
504+ public static Bitmap skew (final Bitmap src ,
505+ final float kx ,
506+ final float ky ,
507+ final float px ,
508+ final float py ) {
469509 return skew (src , kx , ky , px , py , false );
470510 }
471511
@@ -480,7 +520,12 @@ public static Bitmap skew(final Bitmap src, final float kx, final float ky, fina
480520 * @param recycle 是否回收
481521 * @return 倾斜后的图片
482522 */
483- public static Bitmap skew (final Bitmap src , final float kx , final float ky , final float px , final float py , final boolean recycle ) {
523+ public static Bitmap skew (final Bitmap src ,
524+ final float kx ,
525+ final float ky ,
526+ final float px ,
527+ final float py ,
528+ final boolean recycle ) {
484529 if (isEmptyBitmap (src )) return null ;
485530 Matrix matrix = new Matrix ();
486531 matrix .setSkew (kx , ky , px , py );
@@ -498,7 +543,10 @@ public static Bitmap skew(final Bitmap src, final float kx, final float ky, fina
498543 * @param py 旋转点纵坐标
499544 * @return 旋转后的图片
500545 */
501- public static Bitmap rotate (final Bitmap src , final int degrees , final float px , final float py ) {
546+ public static Bitmap rotate (final Bitmap src ,
547+ final int degrees ,
548+ final float px ,
549+ final float py ) {
502550 return rotate (src , degrees , px , py , false );
503551 }
504552
@@ -512,7 +560,11 @@ public static Bitmap rotate(final Bitmap src, final int degrees, final float px,
512560 * @param recycle 是否回收
513561 * @return 旋转后的图片
514562 */
515- public static Bitmap rotate (final Bitmap src , final int degrees , final float px , final float py , final boolean recycle ) {
563+ public static Bitmap rotate (final Bitmap src ,
564+ final int degrees ,
565+ final float px ,
566+ final float py ,
567+ final boolean recycle ) {
516568 if (isEmptyBitmap (src )) return null ;
517569 if (degrees == 0 ) return src ;
518570 Matrix matrix = new Matrix ();
@@ -1102,8 +1154,10 @@ public static Bitmap renderScriptBlur(final Bitmap src,
11021154 try {
11031155 rs = RenderScript .create (Utils .getApp ());
11041156 rs .setMessageHandler (new RenderScript .RSMessageHandler ());
1105- Allocation input = Allocation .createFromBitmap (rs , ret , Allocation .MipmapControl .MIPMAP_NONE , Allocation
1106- .USAGE_SCRIPT );
1157+ Allocation input = Allocation .createFromBitmap (rs ,
1158+ ret ,
1159+ Allocation .MipmapControl .MIPMAP_NONE ,
1160+ Allocation .USAGE_SCRIPT );
11071161 Allocation output = Allocation .createTyped (rs , input .getType ());
11081162 ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur .create (rs , Element .U8_4 (rs ));
11091163 blurScript .setInput (input );
@@ -1343,7 +1397,9 @@ public static Bitmap stackBlur(final Bitmap src, final int radius, final boolean
13431397 * @param format 格式
13441398 * @return {@code true}: 成功<br>{@code false}: 失败
13451399 */
1346- public static boolean save (final Bitmap src , final String filePath , final CompressFormat format ) {
1400+ public static boolean save (final Bitmap src ,
1401+ final String filePath ,
1402+ final CompressFormat format ) {
13471403 return save (src , getFileByPath (filePath ), format , false );
13481404 }
13491405
@@ -1368,7 +1424,10 @@ public static boolean save(final Bitmap src, final File file, final CompressForm
13681424 * @param recycle 是否回收
13691425 * @return {@code true}: 成功<br>{@code false}: 失败
13701426 */
1371- public static boolean save (final Bitmap src , final String filePath , final CompressFormat format , final boolean recycle ) {
1427+ public static boolean save (final Bitmap src ,
1428+ final String filePath ,
1429+ final CompressFormat format ,
1430+ final boolean recycle ) {
13721431 return save (src , getFileByPath (filePath ), format , recycle );
13731432 }
13741433
@@ -1381,7 +1440,10 @@ public static boolean save(final Bitmap src, final String filePath, final Compre
13811440 * @param recycle 是否回收
13821441 * @return {@code true}: 成功<br>{@code false}: 失败
13831442 */
1384- public static boolean save (final Bitmap src , final File file , final CompressFormat format , final boolean recycle ) {
1443+ public static boolean save (final Bitmap src ,
1444+ final File file ,
1445+ final CompressFormat format ,
1446+ final boolean recycle ) {
13851447 if (isEmptyBitmap (src ) || !createFileByDeleteOldFile (file )) return false ;
13861448 OutputStream os = null ;
13871449 boolean ret = false ;
@@ -1528,7 +1590,9 @@ private static boolean isEmptyBitmap(final Bitmap src) {
15281590 * @param newHeight 新高度
15291591 * @return 缩放压缩后的图片
15301592 */
1531- public static Bitmap compressByScale (final Bitmap src , final int newWidth , final int newHeight ) {
1593+ public static Bitmap compressByScale (final Bitmap src ,
1594+ final int newWidth ,
1595+ final int newHeight ) {
15321596 return scale (src , newWidth , newHeight , false );
15331597 }
15341598
@@ -1541,7 +1605,10 @@ public static Bitmap compressByScale(final Bitmap src, final int newWidth, final
15411605 * @param recycle 是否回收
15421606 * @return 缩放压缩后的图片
15431607 */
1544- public static Bitmap compressByScale (final Bitmap src , final int newWidth , final int newHeight , final boolean recycle ) {
1608+ public static Bitmap compressByScale (final Bitmap src ,
1609+ final int newWidth ,
1610+ final int newHeight ,
1611+ final boolean recycle ) {
15451612 return scale (src , newWidth , newHeight , recycle );
15461613 }
15471614
@@ -1553,7 +1620,9 @@ public static Bitmap compressByScale(final Bitmap src, final int newWidth, final
15531620 * @param scaleHeight 缩放高度倍数
15541621 * @return 缩放压缩后的图片
15551622 */
1556- public static Bitmap compressByScale (final Bitmap src , final float scaleWidth , final float scaleHeight ) {
1623+ public static Bitmap compressByScale (final Bitmap src ,
1624+ final float scaleWidth ,
1625+ final float scaleHeight ) {
15571626 return scale (src , scaleWidth , scaleHeight , false );
15581627 }
15591628
@@ -1566,7 +1635,10 @@ public static Bitmap compressByScale(final Bitmap src, final float scaleWidth, f
15661635 * @param recycle 是否回收
15671636 * @return 缩放压缩后的图片
15681637 */
1569- public static Bitmap compressByScale (final Bitmap src , final float scaleWidth , final float scaleHeight , final boolean recycle ) {
1638+ public static Bitmap compressByScale (final Bitmap src ,
1639+ final float scaleWidth ,
1640+ final float scaleHeight ,
1641+ final boolean recycle ) {
15701642 return scale (src , scaleWidth , scaleHeight , recycle );
15711643 }
15721644
@@ -1577,7 +1649,8 @@ public static Bitmap compressByScale(final Bitmap src, final float scaleWidth, f
15771649 * @param quality 质量
15781650 * @return 质量压缩后的图片
15791651 */
1580- public static Bitmap compressByQuality (final Bitmap src , @ IntRange (from = 0 , to = 100 ) final int quality ) {
1652+ public static Bitmap compressByQuality (final Bitmap src ,
1653+ @ IntRange (from = 0 , to = 100 ) final int quality ) {
15811654 return compressByQuality (src , quality , false );
15821655 }
15831656
@@ -1589,7 +1662,9 @@ public static Bitmap compressByQuality(final Bitmap src, @IntRange(from = 0, to
15891662 * @param recycle 是否回收
15901663 * @return 质量压缩后的图片
15911664 */
1592- public static Bitmap compressByQuality (final Bitmap src , @ IntRange (from = 0 , to = 100 ) final int quality , final boolean recycle ) {
1665+ public static Bitmap compressByQuality (final Bitmap src ,
1666+ @ IntRange (from = 0 , to = 100 ) final int quality ,
1667+ final boolean recycle ) {
15931668 if (isEmptyBitmap (src )) return null ;
15941669 ByteArrayOutputStream baos = new ByteArrayOutputStream ();
15951670 src .compress (Bitmap .CompressFormat .JPEG , quality , baos );
@@ -1617,7 +1692,9 @@ public static Bitmap compressByQuality(final Bitmap src, final long maxByteSize)
16171692 * @param recycle 是否回收
16181693 * @return 质量压缩压缩过的图片
16191694 */
1620- public static Bitmap compressByQuality (final Bitmap src , final long maxByteSize , final boolean recycle ) {
1695+ public static Bitmap compressByQuality (final Bitmap src ,
1696+ final long maxByteSize ,
1697+ final boolean recycle ) {
16211698 if (isEmptyBitmap (src ) || maxByteSize <= 0 ) return null ;
16221699 ByteArrayOutputStream baos = new ByteArrayOutputStream ();
16231700 src .compress (CompressFormat .JPEG , 100 , baos );
@@ -1678,7 +1755,9 @@ public static Bitmap compressBySampleSize(final Bitmap src, final int sampleSize
16781755 * @param recycle 是否回收
16791756 * @return 按采样率压缩后的图片
16801757 */
1681- public static Bitmap compressBySampleSize (final Bitmap src , final int sampleSize , final boolean recycle ) {
1758+ public static Bitmap compressBySampleSize (final Bitmap src ,
1759+ final int sampleSize ,
1760+ final boolean recycle ) {
16821761 if (isEmptyBitmap (src )) return null ;
16831762 BitmapFactory .Options options = new BitmapFactory .Options ();
16841763 options .inSampleSize = sampleSize ;
@@ -1697,7 +1776,9 @@ public static Bitmap compressBySampleSize(final Bitmap src, final int sampleSize
16971776 * @param maxHeight 最大高度
16981777 * @return 按采样率压缩后的图片
16991778 */
1700- public static Bitmap compressBySampleSize (final Bitmap src , final int maxWidth , final int maxHeight ) {
1779+ public static Bitmap compressBySampleSize (final Bitmap src ,
1780+ final int maxWidth ,
1781+ final int maxHeight ) {
17011782 return compressBySampleSize (src , maxWidth , maxHeight , false );
17021783 }
17031784
@@ -1710,7 +1791,10 @@ public static Bitmap compressBySampleSize(final Bitmap src, final int maxWidth,
17101791 * @param recycle 是否回收
17111792 * @return 按采样率压缩后的图片
17121793 */
1713- public static Bitmap compressBySampleSize (final Bitmap src , final int maxWidth , final int maxHeight , final boolean recycle ) {
1794+ public static Bitmap compressBySampleSize (final Bitmap src ,
1795+ final int maxWidth ,
1796+ final int maxHeight ,
1797+ final boolean recycle ) {
17141798 if (isEmptyBitmap (src )) return null ;
17151799 BitmapFactory .Options options = new BitmapFactory .Options ();
17161800 options .inJustDecodeBounds = true ;
0 commit comments