Pre-guess size of Bitmap from the actual Uri, before scale-loading

前端 未结 1 990
难免孤独
难免孤独 2020-12-09 04:38

If you have a Uri and you need the Bitmap, you could theoretically do this

Bitmap troublinglyLargeBmp =
  MediaStore.Images.Media.getBitmap(
            


        
相关标签:
1条回答
  • 2020-12-09 05:23

    See the Android guide to handling large bitmaps.

    Specifically this section:

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(getResources(), R.id.myimage, options);
    int imageHeight = options.outHeight;
    int imageWidth = options.outWidth;
    String imageType = options.outMimeType;
    

    EDIT

    In your case, you'll replace the decodeResource line with:

    BitmapFactory.decodeFileDescriptor(fileDescriptor.getFileDescriptor(), null, options);
    
    0 讨论(0)
提交回复
热议问题