Decode a part of Bitmap from file in Android

后端 未结 6 1337
广开言路
广开言路 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条回答
  •  -上瘾入骨i
    2020-12-17 02:09

    try this code:

    private Bitmap decodeFile(File f) {
        Bitmap b = null;
        try {
            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;
            FileInputStream fis = new FileInputStream(f);
            b=Bitmap.createBitmap(BitmapFactory.decodeStream(fis, null, o), 100, 200, 200, 400, null, null);
            fis.close();
        } catch (IOException e) {
        }
        return b;
    }
    

    Am not sure, but this may give some idea to you

提交回复
热议问题