• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to parsel bitmap image into another activity

Nagori

Newbie

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);
 
Try this. To package into an Intent:

Code:
Intent i = new Intent(this, NextActivity.class);
Bitmap b; // your bitmap
ByteArrayOutputStream bs = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.PNG, 50, bs);
i.putExtra("byteArray", bs.toByteArray());
startActivity(i);

And in the receiving Activity:

Code:
if(getIntent().hasExtra("byteArray")) {
   ImageView previewThumbnail = new ImageView(this);
   Bitmap b = BitmapFactory.decodeByteArray(
                   getIntent().getByteArrayExtra("byteArray"),0,getIntent()
                   .getByteArrayExtra("byteArray").length);       
   previewThumbnail.setImageBitmap(b);
}


https://stackoverflow.com/questions/12908048/passing-bitmap-between-two-activities
 
@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);
}
 
If your application crashed it will have generated a stack trace in the Logcat view. This contains essential information required to diagnose the problem.
 
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()
 
Back
Top Bottom