2

I stuck in out of memory. I’m trying to load an image with byte array but what ever i’ve done it wouldn’t work. I get bitmap decoder error I guess. These are all code :

       String password = prefs.getString("BookKey", "");
       BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));
       buf.read(bytes, 0, bytes.length);
       buf.close();
       byte[] bytesdecrpy = decrypt(bytes, password);

       BitmapFactory.Options options = new BitmapFactory.Options();
       options.inDither = true;
       options.inJustDecodeBounds = false;
       options.inPreferredConfig = Bitmap.Config.ARGB_8888;
       options.inTempStorage = new byte[32 * 1024];
       options.inBitmap = BitmapFactory.decodeByteArray(bytesdecrpy, 0,
               bytesdecrpy.length, options);

       bm = Bitmap.createBitmap(options.outWidth,
               options.outHeight, Bitmap.Config.ARGB_8888);

       imageView.setImage(ImageSource.bitmap(bm));

I read as a byte array my encrypt png from device file but i having problem that when i create bitmap for bitmap variable. I still couldn’t run as well for 2 days. If anyone can help me to solve this problem it would be great. Thank you.

EDIT

I've tried only decode my byte array to bitmap like this but problem never changed i've started get problem in decode then

       bm = BitmapFactory.decodeByteArray(bytesdecrpy, 0,
               bytesdecrpy.length, options);
2
  • 1
    Could you please provide the stack trace as well as the size of your image and where are you running your code from? Commented Feb 27, 2016 at 23:30
  • about 100-200kb and android studio if you meant that Commented Feb 27, 2016 at 23:40

1 Answer 1

0

This can cause OOM Exception if the bitmap is too large You could use a background thread to decode and load an image in the container or use a caching technique as explained in https://developer.android.com/training/displaying-bitmaps/index.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.