1

I try to decode a bitmap(1920x1920) from res/raw folder,which is an png resource.I need the full-scale bitmap. I want to use the BimtapFactory.decodeFileDescriptor rather than BitmapFactory.decodeFile||decodeResource because the higher reliability than others to handle OOM: While I try this code,The bitmap is NULL!!! But the file is not null. I've been playing hard. Help Please!

        Context mCtx=MainActivity.this;
        Bitmap bm = null;             
        //id is the resId in res/raw
        AssetFileDescriptor file =mCtx.getResources().openRawResourceFd(R.raw.skin_default_0);
        bm = BitmapFactory.decodeFileDescriptor(file.getFileDescriptor(), null,
                options);
WZY
  • 211
  • 1
  • 3
  • 10

1 Answers1

1
InputStream bm = getResources().openRawResource(R.raw.splash);
    BufferedInputStream bufferedInputStream = new BufferedInputStream(bm);
    Bitmap bmp = BitmapFactory.decodeStream(bufferedInputStream);
    int nh = (int) (bmp.getHeight() * (512.0 / bmp.getWidth()));
    bmp = Bitmap.createScaledBitmap(bmp, 512, nh, true);
    view.setImageBitmap(bmp);

Try this code.

Raw folder - keeping the files as uncompressed. I dont think so , that the BitmapFactory.decodeFileDescriptor will give u efficient result when comparing with the BitmapFactory.decodeStream, Get the inputStream of the file and decode it. if u think the image is too big and u r using many images like this ur app is going to be very heavy, since the raw folder files willnt be compressed. if u want to scaled bitmap use the snippet code that i have added with my code. will give u a better understanding i thnk.

Thanks...

Tamilselvan Kalimuthu
  • 1,534
  • 1
  • 13
  • 28
  • It's said ( http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object ) that decodeFileDescriptor calls different native methods than the decodeStream/decodeFile. I just want to clip the square(1920*1920) image to 1920*1080 without OOM .Any ideas ? – WZY Nov 21 '13 at 04:21