import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
public class PhotoActivity extends Activity {
public static final int NONE = 0;
public static final int PHOTOHRAPH = 1;// Take a photo
public static final int PHOTOZOOM = 2; // Zoom
public static final int PHOTORESOULT = 3;// Results
public static final String IMAGE_UNSPECIFIED = "image/*";
ImageView imageView = null;
Button button0 = null;
Button button1 = null;
@Override
public void onCreate(Bundle savedInstanceState) {
(savedInstanceState);
setContentView();
imageView = (ImageView) findViewById();
button0 = (Button) findViewById(.btn_01);
button1 = (Button) findViewById(.btn_02);
(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK, null);
(
.EXTERNAL_CONTENT_URI,
IMAGE_UNSPECIFIED);
startActivityForResult(intent, PHOTOZOOM);
}
});
(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
(MediaStore.EXTRA_OUTPUT, (new File(
(), "")));
startActivityForResult(intent, PHOTOHRAPH);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == NONE)
return;
// Photograph
if (requestCode == PHOTOHRAPH) {
// Set the file saving path here to put it in the following directory.
File picture = new File(()
+ "/");
startPhotoZoom((picture));
}
if (data == null)
return;
// Read the photo album zoom picture
if (requestCode == PHOTOZOOM) {
startPhotoZoom(());
}
// Processing results
if (requestCode == PHOTORESOULT) {
Bundle extras = ();
if (extras != null) {
Bitmap photo = ("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
(, 75, stream);// (0 -
// 100)Compressed file
(photo);
}
}
(requestCode, resultCode, data);
}
public void startPhotoZoom(Uri uri) {
Intent intent = new Intent("");
(uri, IMAGE_UNSPECIFIED);
("crop", "true");
// aspectX aspectY is the ratio of width and height
("aspectX", 1);
("aspectY", 1);
// outputX outputY is the cropped image width?
("outputX", 64);
("outputY", 64);
("return-data", true);
startActivityForResult(intent, PHOTORESOULT);
}
}