-
Notifications
You must be signed in to change notification settings - Fork 3
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
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
android/src/main/java/com/fenger/package_manager/package_manager/utils/Base64Utils.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,16 @@ | ||
package com.fenger.package_manager.package_manager.utils; | ||
|
||
import android.graphics.Bitmap; | ||
import android.util.Base64; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
|
||
public class Base64Utils { | ||
|
||
public static String encodeToBase64(Bitmap image, Bitmap.CompressFormat compressFormat, int quality) { | ||
ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream(); | ||
image.compress(compressFormat, quality, byteArrayOS); | ||
return Base64.encodeToString(byteArrayOS.toByteArray(), Base64.NO_WRAP); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
android/src/main/java/com/fenger/package_manager/package_manager/utils/DrawableUtils.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,22 @@ | ||
package com.fenger.package_manager.package_manager.utils; | ||
|
||
import android.graphics.Bitmap; | ||
import android.graphics.Canvas; | ||
import android.graphics.drawable.Drawable; | ||
|
||
public class DrawableUtils { | ||
|
||
public static Bitmap getBitmapFromDrawable(Drawable drawable) { | ||
final Bitmap bmp = Bitmap.createBitmap( | ||
drawable.getIntrinsicWidth(), | ||
drawable.getIntrinsicHeight(), | ||
Bitmap.Config.ARGB_8888); | ||
|
||
final Canvas canvas = new Canvas(bmp); | ||
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); | ||
drawable.draw(canvas); | ||
|
||
return bmp; | ||
} | ||
|
||
} |