5

I have a base image view which can load image from sd card. The user can add templates(bitmap images) on to this image view on a button click and can position the added image to user need. I want to save these multiple images as a single image to sd card. How can i do this?

Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
Froyo
  • 455
  • 1
  • 8
  • 21

2 Answers2

3

You can simply get the DrawingCache of your ImageView, then convert it to Bitmap and then save it to SDCARD.

imageview.setDrawingCacheEnabled(true);
Bitmap b = imageview.getDrawingCache();
b.compress(CompressFormat.JPEG, 100, new FileOutputStream("/sdcard/image.jpg"));

You might have to set the SDCARD write permission in manifest.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Andro Selva
  • 53,910
  • 52
  • 193
  • 240
3

Take a look at this Snippet :

How to merge multiple images into one image - Java ImageIO

int rows = 2;   //we assume the no. of rows and cols are known and each chunk has equal width and height  
        int cols = 2;  
        int chunks = rows * cols;  

        int chunkWidth, chunkHeight;  
        int type;  
        //fetching image files  
        File[] imgFiles = new File[chunks];  
        for (int i = 0; i < chunks; i++) {  
            imgFiles[i] = new File("archi" + i + ".jpg");  
        }  

       //creating a bufferd image array from image files  
        BufferedImage[] buffImages = new BufferedImage[chunks];  
        for (int i = 0; i < chunks; i++) {  
            buffImages[i] = ImageIO.read(imgFiles[i]);  
        }  
        type = buffImages[0].getType();  
        chunkWidth = buffImages[0].getWidth();  
        chunkHeight = buffImages[0].getHeight();  

        //Initializing the final image  
        BufferedImage finalImg = new BufferedImage(chunkWidth*cols, chunkHeight*rows, type);  

        int num = 0;  
        for (int i = 0; i < rows; i++) {  
            for (int j = 0; j < cols; j++) {  
                finalImg.createGraphics().drawImage(buffImages[num], chunkWidth * j, chunkHeight * i, null);  
                num++;  
            }  
        }  
        System.out.println("Image concatenated.....");  
        ImageIO.write(finalImg, "jpeg", new File("finalImg.jpg"));  
Venky
  • 11,049
  • 5
  • 49
  • 66