Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » PHP Development Tools (PDT) » Need help taking and displaying multiple photos on the same layout(Creating a triptych application (school project))
Need help taking and displaying multiple photos on the same layout [message #1690927] Wed, 01 April 2015 01:36
Harrison Gibbins is currently offline Harrison GibbinsFriend
Messages: 1
Registered: April 2015
Junior Member
I have watch a tutorial to take photos and display them on an application that I created. I would like to make an application (for school project) that allows you to take 3 photos and display the 3 photos close to each other which makes a triptych. (boring app, my teacher is into arty shit) I have the code for taking and displaying the photo. Its in a "MainActivity" file, I then copied and created a new "MainActivity2" with the same code replacing the first button to another button that I have. Im not very good at explaining but I want 3 buttons, you click on each button and take a separate photo which displays the photo on the button you clicked on. It should look like [] [] []. Each square will be a button, you click that button and take a photo, it will display the photo in the button area [P] [P] [P]. Here is the code for taking the photo and displaying the photo.

My question is, do I create a hole new activity file for activating the next button or do I do it on the same activity?

package com.example.camera;

import java.io.File;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends Activity {

// label our logs "CameraApp3"
private static String logtag = "CameraApp3";
// tells us which camera to take a picture from
private static int TAKE_PICTURE = 1;
// empty variable to hold our image Uri once we store it
private Uri imageUri;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// look for the button we set in the view
Button cameraButton = (Button)findViewById(R.id.button_camera1);
// set a listener on the button
cameraButton.setOnClickListener(cameraListener);


}

// set a new listener
private OnClickListener cameraListener = new OnClickListener() {
public void onClick(View v) {
// open the camera and pass in the current view
takePhoto(v);
}
};

public void takePhoto(View v) {
// tell the phone we want to use the camera
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
// create a new temp file called pic.jpg in the "pictures" storage area of the phone
File photo = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "pic.jpg");
// take the return data and store it in the temp file "pic.jpg"
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
// stor the temp photo uri so we can find it later
imageUri = Uri.fromFile(photo);
// start the camera
startActivityForResult(intent, TAKE_PICTURE);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

// override the original activity result function
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// call the parent
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {
// if the requestCode was equal to our camera code (1) then...
case 1:
// if the user took a photo and selected the photo to use
if(resultCode == Activity.RESULT_OK) {
// get the image uri from earlier
Uri selectedImage = imageUri;
// notify any apps of any changes we make
getContentResolver().notifyChange(selectedImage, null);
// get the imageView we set in our view earlier
ImageView imageView = (ImageView)findViewById(R.id.image_view_camera);
// create a content resolver object which will allow us to access the image file at the uri above
ContentResolver cr = getContentResolver();
// create an empty bitmap object
Bitmap bitmap;
try {
// get the bitmap from the image uri using the content resolver api to get the image
bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, selectedImage);
// set the bitmap to the image view
imageView.setImageBitmap(bitmap);
// notify the user
Toast.makeText(MainActivity.this, selectedImage.toString(), Toast.LENGTH_LONG).show();
} catch(Exception e) {
// notify the user
Toast.makeText(MainActivity.this, "failed to load", Toast.LENGTH_LONG).show();
Log.e(logtag, e.toString());
}
}
}
}

}
Previous Topic:The formatter joins multiline string on a single line
Next Topic:Anonmyous member in Ouline view
Goto Forum:
  


Current Time: Tue Mar 19 08:28:53 GMT 2024

Powered by FUDForum. Page generated in 0.01990 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top