How to Add bitmaps from Camera Activity Dynamically to Gallery

So I spent a few hours this morrning looking for a demo on how to add bitmaps that I got from the Camera Activity Dynamicly to a Gallery View.  Here is the code I came up with.  Let me know if there is a better way.

import java.util.ArrayList;
import java.util.Stack;
import java.util.Vector;

import android.content.Context;
import android.content.Intent;
import android.hardware.Camera;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageView;

public class Pictures extends Activity implements OnClickListener {
    private static final int PICTURE_RESULT = 1;
    Context ctx = null;
    Button next = null;
    Button addPhoto = null;
    Gallery gal = null;
    ImageAdapter images =null;

    public void onCreate(Bundle savedInstanceState) {
        ctx = this.getBaseContext();

        next = (Button) this.findViewById(;

        addPhoto = (Button) this.findViewById(;

        images = new ImageAdapter(this);
        gal = (Gallery) this.findViewById(;


    public void onClick(View v) {
        if (v == next) {
        } else if (v == addPhoto) {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            this.startActivityForResult(intent, PICTURE_RESULT);


    public void onActivityResult(int reqCode, int resultCode, Intent data) {
        super.onActivityResult(reqCode, resultCode, data);
        if (reqCode == PICTURE_RESULT) {
             if (resultCode == Activity.RESULT_OK) {
                     Bundle b = data.getExtras();
                     Bitmap pic = (Bitmap) b.get("data");

                     if (pic != null) {
                         gal.setAdapter(images);  //forces the gallery to add the new images.

    public class ImageAdapter extends BaseAdapter {
        private Context mContext;
        private Vector<Bitmap> images = new Vector<Bitmap>();

        public ImageAdapter(Context c) {
            mContext = c;
        public void AddImage(Bitmap b)

        public int getCount() {
            return images.size();

        public Object getItem(int arg0) {
            return images.get(arg0);

        public long getItemId(int arg0) {
            return arg0;

        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView img;
            if(convertView ==null)
                img = new ImageView(mContext);
                img = (ImageView)convertView;
            return img;


And the xml layout:

<?xml version="1.0" encoding="utf-8"?>
android:text="Add Photo"

27 thoughts on “How to Add bitmaps from Camera Activity Dynamically to Gallery”

  1. I’m new to android coding and the only thing that keeps me from testing this is Getters.class? Is this a class that you have created that I’m missing… I’ve been waiting for this code in leiu of other code that I have written or found.

  2. Sorry about that, its from the project I’m working on. You can just remove the line:

    startActivity(new Intent(ctx, Getters.class));

    I will update the article.

  3. Gday very nice web-site! Male. Beautiful. Fantastic. I’ll bookmark your blog and grab the bottles additionally? I’m pleased to get quite a few useful details below inside upload, we really wish for workout additional tactics in connection with this, thank you for expressing.

  4. dark colored, pink, white-colored as well as lemon. These kind of hues can be blended about the same supplement. Many of the trademarks widely available How to Add bitmaps from Camera Activity Dynamically to Gallery » James Becwar セイコー 腕時計 are generally Air flow maximum 2011, Fresh air Greatest extent 09, Surroundings Maximum 85, Fresh air Utmost 92, Fresh air Optimum 24-7, Atmosphere Utmost 87,

  5. ts while in the heritage with the organization. Just one How to Add bitmaps from Camera Activity Dynamically to Gallery » James Becwar with the key reason why a shoes and boots ended up being therefore cost-effective home ended up being them to had been motivated by thus known as entire world game–soccer. Kobe contains a solid need to be throughout ownership in the footwear.

  6. deborah often about on-line public sale market internet sites. No matter whether anyone lso are taking into consideration purchasing a Gucci free occasion awaiting oneself or even How to Add bitmaps from Camera Activity Dynamically to Gallery » James Becwar as a superb gift idea to be able to anyone ナイキのスニーカー unique, people lmost all obtain the excellent build.

  7. om the woman’s ancestor. The actual elderly release received some sort of manner involving its utilizing excessive top rated minimize, pot single, initial The nike jordan wings company logo and likewise sewn highlighting. For that will home on the contrary, this more recent edition How to Add bitmaps from Camera Activity Dynamically to Gallery » James Becwar offers for being reduce as well as.

  8. Dalla sua nascita la compagnia ha ottenuto oltre 30 riconoscimenti internazionali incentivati anche dalla soddisfazione dei viaggiatori nel servizio globale. Etihad Airways si aggiudicata il titolo di “World Leading Airline” per 5 anni consecutivi: 2009, 2010, 2011, 2012 e 2013.

    1. An fascinating talk is worth a observe. I think that it is finest to engrave further proceeding this subject, it won’t be a forbid area under discussion on the contrary typically persons are not safistactory to talk resting on such topics. To the next. Cheers

  9. In 1968, King was gunned down on the balcony of Memphis Lorraine Motel. The event resulted in several days of racially motivated rioting in the city and directly caused the economic decline of Memphis over the next decade. The motel has been preserved by the National Civil Rights Museum, which is housed at the site.

  10. Il est ensuite nécessaire de découper chacune des parties nécessaires au montage du sac, numériquement ou à l’emporte pièce. Pour cela, tout le savoir faire de la coupeuse est nécessaire. Le cuir étant une matière vivante, une même peau présentera des nuances. L’ouvrière dont c’est le métier saura les assortir afin d’obtenir la bonne homogénéité au moment du montage final.

  11. Thanks for ones marvelous posting! I really enjoyed reading it, you’re a great author.I will make certain to bookmark your blog and definitely will come back sometime soon. I want to encourage you to definitely continue your great work,
    have a nice holiday weekend!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>