Skip to content Skip to sidebar Skip to footer

Converting An Entire Layout To An Image/bitmap

I have been having an issue with this one line of code for a while and I would really apreciate it if any of you have ideaas about it. What I am trying to do is, save a specific la

Solution 1:

The reason is you're trying to pass a Bitmap around using an Intent. Although it's theoretically possible, the size of the Bitmap causes a problems as shown by your error:

E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 3602192)

If you want to pass an Bitmap to another activity, then I'd suggest:

  1. Save the Bitmap to a file

    Add these to your manifest.xml

    <uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" /><uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE" />

    Then the below code should work

    FilebitmapFile=newFile(Environment.getExternalStorageDirectory() + "MyBitmap" + ".png");
    FileOutputStreamfos=newFileOutputStream(bitmapFile);  
    bitmap.compress(Bitmap.CompressFormat.PNG, 80, fos);
    fos.flush();
    fos.close();  
    
  2. Send the filepath as a String to the next activity using Intent/Bundle

    intent.putExtra("filename", "MyBitmap.png");
    
  3. Use the filepath in the next activity to recreate the Bitmap

    StringfileName= getIntent().getStringExtra("filename");
    StringfilePath= Environment.getExternalStorageDirectory() + fileName;
    Bitmapbitmap= BitmapFactory.decodeFile(filePath);
    

Post a Comment for "Converting An Entire Layout To An Image/bitmap"