1. Download our Official Android App: Forums for Android!

Apps How to parsel bitmap image into another activity

Discussion in 'Android Development' started by Nagori, Apr 15, 2019.

  1. Nagori

    Nagori Newbie
    Thread Starter
    Rank:
     #905
    Points:
    15
    Posts:
    12
    Joined:
    Feb 7, 2019

    Feb 7, 2019
    12
    0
    15

    This is my image capture method


    imageView = findViewById(R.id.image_prievew);
    findViewById(R.id.btn_image_capture).setOnClickListener(v -> {
    captureBitmap(bitmap -> {
    new Handler().post(() -> {
    String imagePath = getImageFilePath();
    saveAsPngImage(bitmap, imagePath);
    exportPngToGallery(getApplicationContext(), imagePath);
    imageView.setImageBitmap((bitmap));
    });
    });
    });

    I used this method in my first activity just below of image capture method(Activity 1)

    findViewById(R.id.image_prievew).setOnClickListener(new View.OnClickListener() {
    @override
    public void onClick(View v) {
    Bitmap receipt = BitmapFactory.decodeFile(bitmap.toString());

    Intent intent = new Intent(BaseCameraActivity.this,ImageCaptureListner.class);
    intent.putExtra("Bmp",receipt); //Optional parameters
    startActivity(intent);
    }
    });

    I want to pass above captured image into this activity but it showing error:(Activity 2)

    imageView = (ImageView) findViewById(R.id.image_bitmap);

    Bitmap bitmap = getIntent().getExtras().getParcelable("Bmp");
    imageView.setImageBitmap(bitmap);
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #10
    Points:
    1,988
    Posts:
    8,803
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    8,803
    13,122
    1,988
    Male
    Software developer
    South West of England
    Try this. To package into an Intent:

    Code (Text):
    1.  
    2. Intent i = new Intent(this, NextActivity.class);
    3. Bitmap b; // your bitmap
    4. ByteArrayOutputStream bs = new ByteArrayOutputStream();
    5. b.compress(Bitmap.CompressFormat.PNG, 50, bs);
    6. i.putExtra("byteArray", bs.toByteArray());
    7. startActivity(i);
    8.  
    And in the receiving Activity:

    Code (Text):
    1.  
    2. if(getIntent().hasExtra("byteArray")) {
    3.    ImageView previewThumbnail = new ImageView(this);
    4.    Bitmap b = BitmapFactory.decodeByteArray(
    5.                    getIntent().getByteArrayExtra("byteArray"),0,getIntent()
    6.                    .getByteArrayExtra("byteArray").length);      
    7.    previewThumbnail.setImageBitmap(b);
    8. }
    9.  

    https://stackoverflow.com/questions/12908048/passing-bitmap-between-two-activities
     
    Nagori and GameTheory like this.
  3. Nagori

    Nagori Newbie
    Thread Starter
    Rank:
     #905
    Points:
    15
    Posts:
    12
    Joined:
    Feb 7, 2019

    Feb 7, 2019
    12
    0
    15
  4. Nagori

    Nagori Newbie
    Thread Starter
    Rank:
     #905
    Points:
    15
    Posts:
    12
    Joined:
    Feb 7, 2019

    Feb 7, 2019
    12
    0
    15
    @LV426 I am glad to see your answer and I also see that link and before posting my thread here I tried many other solutions provided in StackOverflow but didn't get it I am sure that I miss something I also tried your code but still getting an error, please Help

    ////image capture
    imageView = findViewById(R.id.image_prievew);
    findViewById(R.id.btn_image_capture).setOnClickListener(v -> {
    captureBitmap(bitmap -> {
    new Handler().post(() -> {
    String imagePath = getImageFilePath();
    saveAsPngImage(bitmap, imagePath);
    exportPngToGallery(getApplicationContext(), imagePath);
    imageView.setImageBitmap((bitmap));

    //Activity for capturing Bitmap

    findViewById(R.id.image_prievew).setOnClickListener(new View.OnClickListener() {
    @override
    public void onClick(View v) {

    Intent i = new Intent(BaseCameraActivity.this, ImageCaptureListner.class);
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 50, bs);
    i.putExtra("byteArray", bs.toByteArray());
    startActivity(i);
    }
    //Activity for recieving

    imageView = (ImageView) findViewById(R.id.image_bitmap);
    if(getIntent().hasExtra("byteArray")) {

    ImageView imageView = new ImageView(this);
    Bitmap bitmap = BitmapFactory.decodeByteArray(
    getIntent().getByteArrayExtra("byteArray"),0,getIntent()
    .getByteArrayExtra("byteArray").length);
    imageView.setImageBitmap(bitmap);
    }
     
  5. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #10
    Points:
    1,988
    Posts:
    8,803
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    8,803
    13,122
    1,988
    Male
    Software developer
    South West of England
    What's the error?
     
  6. Nagori

    Nagori Newbie
    Thread Starter
    Rank:
     #905
    Points:
    15
    Posts:
    12
    Joined:
    Feb 7, 2019

    Feb 7, 2019
    12
    0
    15
    E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 658932)
     
  7. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #10
    Points:
    1,988
    Posts:
    8,803
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    8,803
    13,122
    1,988
    Male
    Software developer
    South West of England
    Need to see a stack trace.
     
  8. Nagori

    Nagori Newbie
    Thread Starter
    Rank:
     #905
    Points:
    15
    Posts:
    12
    Joined:
    Feb 7, 2019

    Feb 7, 2019
    12
    0
    15
    can you please little explain this. Thanks
     
  9. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #10
    Points:
    1,988
    Posts:
    8,803
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    8,803
    13,122
    1,988
    Male
    Software developer
    South West of England
    If your application crashed it will have generated a stack trace in the Logcat view. This contains essential information required to diagnose the problem.
     
  10. Nagori

    Nagori Newbie
    Thread Starter
    Rank:
     #905
    Points:
    15
    Posts:
    12
    Joined:
    Feb 7, 2019

    Feb 7, 2019
    12
    0
    15
    All LogCat errors:

    E/HsmCoreServiceImpl: onTransact in code is: 102
    E/Surface: queueBuffer: error queuing buffer to SurfaceTexture, -32
    E/CameraRender: failed to queue buffer to window!
    E/CameraRender: QS: dqKN=484, qKN=489, qKNF=0, dqSF=476, qSF=476, qSFF=1
    Channel is unrecoverably broken and will be disposed!
    E/FocusManager: enter stopGsensorStatCollect()
     

Share This Page

Loading...