SoFunction
Updated on 2025-03-11

2 ways to pass pictures in Android

Method 1:

The basic idea is to convert bitmap into a byte array first, pass the array with Intent, and convert the array into bitmap
 
Method of converting bitmap into byte array:
 

Copy the codeThe code is as follows:

private byte[] Bitmap2Bytes(Bitmap bm){      
    ByteArrayOutputStream baos = new ByteArrayOutputStream();        
    (, 100, baos);        
    return ();      
   }  
  
Convert the byte array into bitmap method:

Copy the codeThe code is as follows:

byte buff[]=("image");   
bitmap = (buff, 0, );  

Method 2:

Send pictures:

Copy the codeThe code is as follows:

Intent intent  = new Intent( , );   
 ();   
("BITMAP", ()); //You can put a bitmap here
 startActivity(intent);   

Receive pictures:
Copy the codeThe code is as follows:

//Received activity
Intent intent = getIntent();   
if (intent  != null &&  ("BITMAP") != null) {   
    Bitmap bitmap = (Bitmap)getIntent().getParcelableExtra("BITMAP");   
    (bitmap);   
}