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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:05:38+00:00 2026-05-30T05:05:38+00:00

I have a Canvas I draw on, I’m trying to take the bitmap out,

  • 0

I have a Canvas I draw on, I’m trying to take the bitmap out, convert it to a byte array and save it serialized into a file. then later open, deserialize, and apply the bitmap back to the canvas. In the code below everything seems to work well except that when applying the bitmap to canvas nothing appears. can someone please show me where I’m going wrong.

public byte[] getCanvasData(){

    ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
    mBitmap.compress(CompressFormat.PNG, 0, bos); 
    byte[] bitmapdata = bos.toByteArray();
    return bitmapdata;
}

public void setCanvasData(byte[] canvasData, int w, int h){
    mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    mBitmap.eraseColor(0x00000000);
    mCanvas = new Canvas(mBitmap);
    mCanvas.drawBitmap(BitmapFactory.decodeByteArray(canvasData , 0,  canvasData.length).copy(Bitmap.Config.ARGB_8888, true), 0, 0, null);

}

ADDED SOME EXTRA CODE TO POSSIBLY HELP A LITTLE

public void readInSerialisable() throws IOException
{
    FileInputStream fileIn = new FileInputStream("/sdcard/theBKup.ser");

    ObjectInputStream in = new ObjectInputStream(fileIn);


    try
    { 
       BookData book = (BookData) in.readObject();
       pages.clear();
       canvasContainer.removeAllViews();

       for (int i = 0; i < book.getBook().size(); i++){
           Log.d("CREATION", "LOADING PAGE " + i);
           pages.add(new Canvas2(context, book.getPageAt(i), canvasContainer.getWidth(), canvasContainer.getHeight()));
       }

       canvasContainer.addView(pages.get(page), new AbsoluteLayout.LayoutParams(AbsoluteLayout.LayoutParams.FILL_PARENT, AbsoluteLayout.LayoutParams.FILL_PARENT, 0, 0));

       updatePagination();
       Log.d("CREATION", "Updated Pagination");
    }
    catch (Exception exc)
    {
        System.out.println("didnt work");
        exc.printStackTrace();
    }
}

BookData – Serializable class containing all my data, simple gets/sets in there

onDraw Method

 @Override
protected void onDraw(Canvas canvas) {
    Log.d("DRAWING", "WE ARE DRAWING");
    canvas.drawColor(0x00AAAAAA); //MAKE CANVAS TRANSPARENT
    canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
    canvas.drawPath(mPath, mPaint);
}
  • 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-05-30T05:05:39+00:00Added an answer on May 30, 2026 at 5:05 am

    I would do the following 2 tests.

    1. Log some of the byte stream to make sure that it was loaded correctly. Something like Log.v(canvasData[0]+canvasData[1]);, or put a break point there, or something just to make sure the data is correct.
    2. Draw a bitmap that you know is valid, using the same code, and see if it appears correctly.

    I’m not sure exactly what’s going on, but I strongly suspect one of the following.

    1. The byte stream is not being read in correctly.
    2. The bitmap is not being updated to the screen, or is using a trivially small size.

    In the event that your byte stream data has something, then you will want to take a look at the Canvas documentation. Specifically, look at the following bit.

    In order to see a Canvas, it has to be put on to a view. Once it is on a view, the onDraw() command must be called for it to be visible. I would make sure that you are in fact doing an onDraw(), and that the Canvas is associated with the View correctly. If you are using an onDraw() already, please post the bits of code associated with it.

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

Sidebar

Related Questions

I have created a canvas and draw a bitmap on it, and animate it
I have a large module written in JS which uses Canvas to draw and
I have a class which inherits from Canvas. On the OnRender method I draw
How I can draw bezier curve in canvas. I have only start point and
I have an application which uses the canvas to draw the scribbling done by
I have some objects which I draw onto a Canvas as part of a
I have a canvas-based drawing app that when zoomed in, I draw a miniature
In my WPF project I have a canvas on which I draw an ellipse
I have an isometric map which I draw to the canvas. When I try
I have implement the Canvas and paint to draw on canvas. i am able

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.