3

I encounter a "Caused by: java.lang.RuntimeException: Buffer not large enough for pixels " error with the following code snippit:

    String pathName = "/sdcard/test.bmp";
    Bitmap bm1 = BitmapFactory.decodeFile(pathName);

    ShortBuffer buffer = ShortBuffer.allocate(bm1.getWidth()*bm1.getHeight());
    bm1.copyPixelsToBuffer(buffer);

I thought buffer is larget enought since it is allocated according to the Bitmap's width and height. What may be cause of the problem?

bei
  • 221
  • 4
  • 7
  • Did you take a look a this? http://stackoverflow.com/questions/5626795/how-to-get-a-bitmap-from-a-raw-image – 0gravity Aug 13 '12 at 03:14
  • Thanks for the information. I did not try the code from that hyperlink though. Instead, I use a ByteBuffer and I set the buffer size to width*length*4. I am successful with copyPixelsToBuffer() and copyPixelsFromBuffer(), as well as displaying the picture normally. – bei Aug 13 '12 at 06:47
  • See this answer: http://stackoverflow.com/a/23769833/1765169 It solved my issues. – Nj Subedi Nov 29 '14 at 07:17

0 Answers0