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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:39:15+00:00 2026-06-05T19:39:15+00:00

I hava a Bitmap variable named bmp in Activity1 , and I want to

  • 0

I hava a Bitmap variable named bmp in Activity1 , and I want to send the bitmap to Activity2

Following is the code I use to pass it with the intent.

Intent in1 = new Intent(this, Activity2.class);
in1.putExtra("image",bmp);
startActivity(in1);

And in Activity2 I try to access the bitmap using the following code

Bundle ex = getIntent().getExtras();
Bitmap bmp2 = ex.getParceable("image");
ImageView result = (ImageView)findViewById(R.Id.imageView1);
result.setImageBitmap(bmp);

The application runs without an exception but it does not give the expected result

  • 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-05T19:39:16+00:00Added an answer on June 5, 2026 at 7:39 pm

    Convert it to a Byte array before you add it to the intent, send it out, and decode.

    //Convert to byte array
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
    byte[] byteArray = stream.toByteArray();
    
    Intent in1 = new Intent(this, Activity2.class);
    in1.putExtra("image",byteArray);
    

    Then in Activity 2:

    byte[] byteArray = getIntent().getByteArrayExtra("image");
    Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
    

    edit

    Thought I should update this with best practice:

    In your first activity, you should save the Bitmap to disk then load it up in the next activity. Make sure to recycle your bitmap in the first activity to prime it for garbage collection:

    Activity 1:

    try {
        //Write file
        String filename = "bitmap.png";
        FileOutputStream stream = this.openFileOutput(filename, Context.MODE_PRIVATE);
        bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
        
        //Cleanup
        stream.close();
        bmp.recycle();
    
        //Pop intent
        Intent in1 = new Intent(this, Activity2.class);
        in1.putExtra("image", filename);
        startActivity(in1);
    } catch (Exception e) {
        e.printStackTrace();
    }
    

    In Activity 2, load up the bitmap:

    Bitmap bmp = null;
    String filename = getIntent().getStringExtra("image");
    try {
        FileInputStream is = this.openFileInput(filename);
        bmp = BitmapFactory.decodeStream(is);
        is.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for example, I hava a partial template named _header.php, I want to use it
I hava a CSV file that I want to treat as source code. Essentially
i hava a set of following tables customer(cus_id,cus_name); jointAccount(cus_id,acc_number,relationship); account(acc_number,cus_id) now i want to
I hava a perl subroutine where i would like to pass parameters as a
I hava a php variable that contain JSON type data. $list = [{id:10,first_name:first,mi_name:,last_name:last,nick_name:HH}]; and
I hava following sql query SELECT animal_code, ISNULL(SUM(calve_milk + morning + evening), 0) /
I hava a basic Hibernate/JPA question. I want to find a best practice solution
I hava a generic class called ArrayBag. I want to override equals method. So
I hava 2 listvies on the same activity list1 and list2. I want to
I hava a java application that uses Buffers to pass object around between threads.

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.