1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| package com.example.android.accelerometerplay;
import java.util.Vector;
//import mpi.cbg.fly.Feature;
//import mpi.cbg.fly.SIFT;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ImageView;
public class CameraActivity extends Activity {
private static final int PICTURE_RESULT = 9;
private Bitmap mPicture;
private ImageView mView;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mView = (ImageView) findViewById(R.id.view);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.camera:
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
CameraActivity.this.startActivityForResult(camera, PICTURE_RESULT);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void onDestroy() {
super.onDestroy();
if (mPicture != null) {
mPicture.recycle();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if results comes from the camera activity
if (requestCode == PICTURE_RESULT) {
// if a picture was taken
if (resultCode == Activity.RESULT_OK) {
// Free the data of the last picture
if(mPicture != null)
mPicture.recycle();
// Get the picture taken by the user
mPicture = (Bitmap) data.getExtras().get("data");
// Avoid IllegalStateException with Immutable bitmap
Bitmap pic = mPicture.copy(mPicture.getConfig(), true);
mPicture.recycle();
mPicture = pic;
// Show the picture
mView.setImageBitmap(mPicture);
// if user canceled from the camera activity
} else if (resultCode == Activity.RESULT_CANCELED) {
}
}
}
} |
Partager