Decode a part of Bitmap from file in Android

后端 未结 6 1362
广开言路
广开言路 2020-12-17 01:40

I have a file with a very large image: for example 9000x9000.

I can\'t load the Bitmap in memory because the heap size. But I only need to display a small part of th

6条回答
  •  悲&欢浪女
    2020-12-17 02:20

    It can easily be done using RapidDecoder.

    I actually generated a 9000x9000 png which its file size is about 80MB and the 200x400 sized region was successfully loaded.

    import rapid.decoder.BitmapDecoder;
    
    Bitmap bitmap = BitmapDecoder.from("big-image.png")
                                 .region(145, 192, 145 + 200, 192 + 400)
                                 .decode();
    imageView.setImageBitmap(bitmap);
    

    It works for Android 2.2 and above.

提交回复
热议问题