Wallpaper image selection and cropping.

This commit is contained in:
Alan Evans
2021-01-20 17:01:34 -04:00
committed by Greyson Parrelli
parent b5712f4bd1
commit a8ad1e718e
22 changed files with 850 additions and 74 deletions

View File

@@ -10,6 +10,7 @@ import android.graphics.Rect;
import android.graphics.YuvImage;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.Pair;
import androidx.annotation.NonNull;
@@ -267,6 +268,17 @@ public class BitmapUtil {
return stream.toByteArray();
}
public static @Nullable byte[] toWebPByteArray(@Nullable Bitmap bitmap) {
if (bitmap == null) return null;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
if (Build.VERSION.SDK_INT >= 30) {
bitmap.compress(CompressFormat.WEBP_LOSSLESS, 100, stream);
} else {
bitmap.compress(CompressFormat.WEBP, 100, stream);
}
return stream.toByteArray();
}
public static @Nullable Bitmap fromByteArray(@Nullable byte[] bytes) {
if (bytes == null) return null;
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);