Deprecated “getBitmap” with API 29. Any alternative codes?

前端 未结 9 2223
渐次进展
渐次进展 2020-12-15 20:25

My onActivityResult is not working because getBitmap is deprecated, any alternative codes to achieve this?

here are the codes that needs to

9条回答
  •  时光取名叫无心
    2020-12-15 21:02

    You can use this code for creating bitmap

    Bitmap bitmap;
    if (Build.VERSION.SDK_INT >= 29) {
         ImageDecoder.Source source = ImageDecoder.createSource(getApplicationContext().getContentResolver(), imageUri);
         try {
             bitmap = ImageDecoder.decodeBitmap(source);
         } catch (IOException e) {
             e.printStackTrace();
         }
    } else {
         try {
         bitmap = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), imageUri);
         } catch (IOException e) {
              e.printStackTrace();
         }
    }
    

提交回复
热议问题