Skip to content

Commit

Permalink
Added missing utils
Browse files Browse the repository at this point in the history
  • Loading branch information
emvaized committed Nov 20, 2021
1 parent 68afea8 commit c8ccf72
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
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);
}

}
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;
}

}

0 comments on commit c8ccf72

Please sign in to comment.