Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine two images in android java

So i have two images stored locally on an SD card in android and i want to combine them into one image. Its hard to explain so i going to link to a picture for a better example of how i want to take the first two images and combine them into the last.

http://img850.imageshack.us/i/combinedh.jpg/

like image 915
Peter Avatar asked Mar 31 '11 01:03

Peter


1 Answers

I am generally using following function from Jon Simon to combine two Bitmap passed as argument and get combined Bitmap as output,

    public Bitmap combineImages(Bitmap c, Bitmap s) 
{ 
    Bitmap cs = null; 

    int width, height = 0; 

    if(c.getWidth() > s.getWidth()) { 
      width = c.getWidth() + s.getWidth(); 
      height = c.getHeight(); 
    } else { 
      width = s.getWidth() + s.getWidth(); 
      height = c.getHeight(); 
    } 

    cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 

    Canvas comboImage = new Canvas(cs); 

    comboImage.drawBitmap(c, 0f, 0f, null); 
    comboImage.drawBitmap(s, c.getWidth(), 0f, null); 

    return cs; 
}  
like image 99
Hitesh Patel Avatar answered Oct 06 '22 01:10

Hitesh Patel