create source from uri java

Solutions on MaxInterview for create source from uri java by the best coders in the world

showing results for - "create source from uri java"
Maria José
09 Nov 2016
1// depricated getBitmap(resolver, uri) 
2public class BitmapResolver {
3    private final static String TAG = "BitmapResolver";
4
5    @SuppressWarnings("deprecation")
6    private static Bitmap getBitmapLegacy(@NonNull ContentResolver contentResolver, @NonNull Uri fileUri){
7        Bitmap bitmap = null;
8
9        try {
10            bitmap = MediaStore.Images.Media.getBitmap(contentResolver, fileUri);
11        } catch (IOException e) {
12            e.printStackTrace();
13        }
14
15        return bitmap;
16    }
17
18    @TargetApi(Build.VERSION_CODES.P)
19    private static Bitmap getBitmapImageDecoder(@NonNull ContentResolver contentResolver, @NonNull Uri fileUri){
20        Bitmap bitmap = null;
21
22        try {
23            bitmap = ImageDecoder.decodeBitmap(ImageDecoder.createSource(contentResolver, fileUri));
24        } catch (IOException e) {
25            e.printStackTrace();
26        }
27
28        return bitmap;
29    }
30
31    public static Bitmap getBitmap(@NonNull ContentResolver contentResolver, Uri fileUri){
32        if (fileUri == null){
33            Log.i(TAG, "returning null because URI was null");
34            return null;
35        }
36
37        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P){
38            return getBitmapImageDecoder(contentResolver, fileUri);
39        } else{
40            return getBitmapLegacy(contentResolver, fileUri);
41        }
42    }
43   }
44// https://stackoverflow.com/questions/56651444/deprecated-getbitmap-with-api-29-any-alternative-codes