forked from Blankj/AndroidUtilCode
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
370 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
utilcode/src/main/java/com/blankj/utilcode/utils/ImageUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.blankj.utilcode.utils; | ||
|
||
import android.graphics.Bitmap; | ||
import android.graphics.Bitmap.CompressFormat; | ||
import android.graphics.BitmapFactory; | ||
import android.util.Base64; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
|
||
/** | ||
* <pre> | ||
* author: Blankj | ||
* blog : http://blankj.com | ||
* time : 2016/8/12 | ||
* desc : | ||
* </pre> | ||
*/ | ||
public class ImageUtils { | ||
|
||
/** | ||
* 将Bitmap转换成字符串 | ||
* | ||
* @param bitmap | ||
* @return | ||
*/ | ||
public static String bitmaptoString(Bitmap bitmap) { | ||
String string = null; | ||
ByteArrayOutputStream bStream = new ByteArrayOutputStream(); | ||
bitmap.compress(CompressFormat.PNG, 100, bStream); | ||
byte[] bytes = bStream.toByteArray(); | ||
string = Base64.encodeToString(bytes, Base64.DEFAULT); | ||
return string; | ||
} | ||
|
||
/** | ||
* 把byte数组转化成 bitmap对象 | ||
* | ||
* @param b | ||
* @return | ||
*/ | ||
public static Bitmap bytes2Bimap(byte[] b) { | ||
if (b.length != 0) { | ||
return BitmapFactory.decodeByteArray(b, 0, b.length); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.