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

前端 未结 9 2221
渐次进展
渐次进展 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:00

    Have you tried this?

    val bitmap = ImageDecoder.createSource(contentResolver, uri)

    0 讨论(0)
  • 2020-12-15 21:01

    It was evident that the getBitmap API doesn't work with the latest Android SDK - 29. So, this worked for me

    Uri contentURI = data.getData();
    try {
        imageView.setImageURI(contentURI);
    } catch (Exception e) {
        e.printStackTrace();
    }
    

    Please let me know if this doesn't work for any of you, shall other options!

    0 讨论(0)
  • 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();
         }
    }
    
    0 讨论(0)
提交回复
热议问题