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 8582827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:23:33+00:00 2026-06-11T21:23:33+00:00

Hi I have a raw dump of image which i store as byte array

  • 0

Hi I have a raw dump of image which i store as byte array i have to display this on surface view. I tried to convert this byte array into a mutable bitmap and render on the canvas of surface holder but i get this null pointer exception when “drawBitmap” function is called.

BlockquoteE/AndroidRuntime(28358): FATAL EXCEPTION: main
E/AndroidRuntime(28358): java.lang.NullPointerException
E/AndroidRuntime(28358): at android.graphics.Canvas.throwIfRecycled(Canvas.java:1025)
E/AndroidRuntime(28358): at android.graphics.Canvas.drawBitmap(Canvas.java:1065)
Blockquote

This is how i try to render the byte array

    public void surfaceCreated(SurfaceHolder holder) {
         // TODO Auto-generated method stub
              //getting byte array
              byte[] bytes;
    File f1= new File("/data/dump.txt");
    int offset = 0, n = 0;
    InputStream in;
    long length = f1.length();
    bytes = new byte[(int) length];

          try {

          in = new FileInputStream(f1);

           while (offset < bytes.length
                && (n = in.read(bytes, offset, bytes.length - offset))  >= 0) {
            offset += n;

           }
        in.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


              // getting byte array
                Bitmap bmp;
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inMutable = true;
    bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length,options );
              Canvas  canvas = holder.lockCanvas();
            if(canvas != null){

                canvas.drawBitmap(bmp, 0, 0, null); 

              }
            holder.unlockCanvasAndPost(canvas); //finalize          

        }
  • 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-11T21:23:35+00:00Added an answer on June 11, 2026 at 9:23 pm

    Your byte array bytes is never instantiated. So, when you call BitmapFactory.decodeByteArray, it returns null.

    From the Android Reference:

    public static Bitmap decodeByteArray (byte[] data, int offset, int length, BitmapFactory.Options opts)

    Since: API Level 1
    Decode an immutable bitmap from the specified byte array.
    …

    Returns
    The decoded bitmap, or null if the image data could not be decoded, or, if opts is non-null, if opts requested only the size be returned (in opts.outWidth and opts.outHeight)

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

Sidebar

Related Questions

I have written a raw binary image file into a buffer which is an
I have a simulation in Gazebo in which I am publishing an image raw
I have rgb raw data, which is 8 bit/channel, i need to convert it
I have a raw image file that is saved in binary data (no encoding).
I have a raw image buffer in the RGB format. I need to draw
I have an array of raw sound data samples, and I'm trying to make
I have a two dump files of raw video and raw audio from an
I have raw data in a custom image format (canot be changed) that is
I have raw 44,1 kHz audio data from a song as Javascript array and
I have raw observations of 500 numeric values (ranging from 1 to 25000) in

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.