Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8946057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:24:52+00:00 2026-06-15T12:24:52+00:00

I have the following snippet of code. The marked line is causing a BufferUnderflowException.

  • 0

I have the following snippet of code. The marked line is causing a BufferUnderflowException. I read the documentation on the exception but still do not understand what exactly it menas. I use the .rewind() method which I was under the impression mitigates the issue.

Can anyone please enlighten me on the topic or cause of my error?

            Bitmap cameraBaseSized = BitmapFactory.decodeFile(cameraPath, opts);
            Bitmap canvasBlendSized = BitmapFactory.decodeFile(canvasPath, options);
            Bitmap result = cameraBaseSized.copy(Config.ARGB_8888, true);
            IntBuffer buffBase = IntBuffer.allocate(cameraBaseSized.getWidth()
                    * cameraBaseSized.getHeight());
            cameraBaseSized.copyPixelsToBuffer(buffBase);
            buffBase.rewind();
            IntBuffer buffBlend = IntBuffer.allocate(canvasBlendSized.getWidth()
                    * canvasBlendSized.getHeight());
            canvasBlendSized.copyPixelsToBuffer(buffBlend);
            buffBlend.rewind();
            IntBuffer buffOut = IntBuffer.allocate(cameraBaseSized.getWidth()
                    * cameraBaseSized.getHeight());
            buffOut.rewind();
            while (buffOut.position() < buffOut.limit()) {
                int filterInt = buffBlend.get(); //BUFFERUNDERFLOW EXCEPTION
                int srcInt = buffBase.get();
                int redValueFilter = Color.red(filterInt);
                int greenValueFilter = Color.green(filterInt);
                int blueValueFilter = Color.blue(filterInt);
                int redValueSrc = Color.red(srcInt);
                int greenValueSrc = Color.green(srcInt);
                int blueValueSrc = Color.blue(srcInt);
                int redValueFinal = multiply(redValueFilter, redValueSrc);
                int greenValueFinal = multiply(greenValueFilter, greenValueSrc);
                int blueValueFinal = multiply(blueValueFilter, blueValueSrc);
                int pixel = Color.argb(255, redValueFinal, greenValueFinal, blueValueFinal);
                buffOut.put(pixel);
            }
            buffOut.rewind();
            result.copyPixelsFromBuffer(buffOut);

And the exception snippet

11-29 14:41:57.347: E/AndroidRuntime(2166): Caused by: java.nio.BufferUnderflowException
11-29 14:41:57.347: E/AndroidRuntime(2166):     at java.nio.IntArrayBuffer.get(IntArrayBuffer.java:55)

I also would like to add this is happening only on specific devices, particularly samsung flavors.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:24:53+00:00Added an answer on June 15, 2026 at 12:24 pm

    Since it is happening on certain devices, it could be possible that you are not getting the pixel format you are expecting.

    Also if buffBlend is for any reason shorter than buffOut (which could potentially be caused by the bitmaps being different formats), you will get this exception when you try and get() past the end of it.

    EDIT:

    You could change int filterInt = buffBlend.get(); to

    int filterInt = 0;
    if (buffBlend.position() < buffBlend.limit())
        filterInt = buffBlend.get();
    

    If you do that for both of your buffers, that should protect you against the exception, and blend with black when one image is bigger than the other.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code snippet but I am getting wrong output. class Program {
I have the following code snippet to read the full contents of a text
I have the following snippet of code of which I do not have access
I have following code snippet that i use to compile class at the run
I have following code snippet: class ABC{ public: int a; void print(){cout<<hello<<endl;} }; int
I have the following snippet of code: import csv def has_header(first_lines): sniffer = csv.Sniffer()
I have the following snippet of code (I'm using jQuery 1.4.2): $.post('/Ads/GetAdStatsRow/', { 'ad_id':
So I have the following snippet of code: private Nullable<decimal> _excessWages; public decimal ExcessWages
i have the following code snippet in my ANT File which compiles my project
I have the following code snippet where some strings are initialized in the if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.