Here is another way

public static String appendImages(ArrayList<Bitmap> bitmaplist) {

       //assume bitmaplist has atleast 1 bitmap
        Bitmap tmpbitmap = bitmaplist.get(0);

        int w = tmpbitmap.getWidth();
        int h = tmpbitmap.getHeight();

        Bitmap new_image = Bitmap.createBitmap(w, h * bitmaplist.size(),
                tmpbitmap.getConfig());
        int[] pixels = new int[w * (h * bitmaplist.size())];

        int j = 0;

        for (Bitmap uri : bitmaplist) {

            Bitmap mBitmap = uri;

            mBitmap.getPixels(pixels, j * h * w, w, 0, 0, w, h);
            j++;

        }
        new_image.setPixels(pixels, 0, w, 0, 0, w, h * bitmaplist.size());

        String filepath = "/sdcard.jpg";
        File imagefile = new File(filepath);
        try {
            FileOutputStream fos = new FileOutputStream(imagefile);
            new_image.compress(CompressFormat.JPEG, 100, fos);
            fos.flush();
            fos.close();
        }

        catch (Exception e) {

            Log.e("Error in File append", e.getMessage());
        }

        return filepath;

    }

On Thu, Oct 1, 2009 at 8:16 AM, Warrick <[email protected]> wrote:

>
> This code reads a number of images from files and merges them into a
> single image. The merged image is a single column, i.e. each image is
> appended to the merged image below the preceding image. So you'll see
> as the source bitmaps are gleaned from the files a height calculation
> is done. The canvas size is calculated from the maximum width of the
> source images and the sum of the heights of the source images.
>
> You could do your own merge image make up and position the images as
> need be so the height and width calculations may not be relevant in
> your case. In any case you'd need a canvas with dimensions suitable to
> contain all the source images in whatever positions you wish to place
> them.
>
> Hope this helps.
>                                String[] vFilename;
>                                int vImageCount;
>
>                                ...
>
>                                Bitmap[] vSourceBitmaps = new
> Bitmap[vImageCount];
>                                int vWidth = 0;
>                                int vHeight = 0;
>
>                                //Read bitmaps from files
>                                for (int i = 0; i <= vImageCount; i++) {
>                                        vSourceBitmaps[i] =
> BitmapFactory.decodeFile(vFileName[i]);
>                                        vWidth =
> vSourceBitmaps[i].getWidth() > vWidth ? vSourceBitmaps
> [i].getWidth() : vWidth;
>                                        vHeight +=
> vSourceBitmaps[i].getHeight();
>                                }
>
>                                //Merging begins here
>                                Bitmap vTargetBitmap =
> Bitmap.createBitmap(vWidth, vHeight,
> Bitmap.Config.ARGB_8888);
>                                Canvas vCanvas = new Canvas(vTargetBitmap);
>                                int vInsertY = 0;
>                                for (int i = 0; i < vImageCount; i++) {
>
>  vCanvas.drawBitmap(vSourceBitmaps[i], (float)0f, (float)vInsertY,
> null);
>                                        vInsertY +=
> vSourceBitmaps[i].getHeight();
>                                 }
>
>
> On Sep 15, 4:41 pm, chan <[email protected]> wrote:
> > can you give some sample codes for merge several images into a one
> > single image..
> > Thank you advance
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to