Back to project page android-cropimage.
The source code is released under:
Apache License
If you think the Android project android-cropimage listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.android.camera.example; /*from w w w . j a v a 2 s .co m*/ import android.app.Activity; import android.content.Intent; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.ImageView; import com.android.camera.CropImageIntentBuilder; import java.io.File; public class MainActivity extends Activity implements View.OnClickListener { private static int REQUEST_PICTURE = 1; private static int REQUEST_CROP_PICTURE = 2; private Button button; private ImageView imageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button) findViewById(R.id.button); button.setOnClickListener(this); imageView = (ImageView) findViewById(R.id.imageView); } @Override public void onClick(View view) { if (view.equals(button)) { startActivityForResult(MediaStoreUtils.getPickImageIntent(this), REQUEST_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 protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); File croppedImageFile = new File(getFilesDir(), "test.jpg"); if ((requestCode == REQUEST_PICTURE) && (resultCode == RESULT_OK)) { // When the user is done picking a picture, let's start the CropImage Activity, // setting the output image file and size to 200x200 pixels square. Uri croppedImage = Uri.fromFile(croppedImageFile); CropImageIntentBuilder cropImage = new CropImageIntentBuilder(200, 200, croppedImage); cropImage.setSourceImage(data.getData()); startActivityForResult(cropImage.getIntent(this), REQUEST_CROP_PICTURE); } else if ((requestCode == REQUEST_CROP_PICTURE) && (resultCode == RESULT_OK)) { // When we are done cropping, display it in the ImageView. imageView.setImageBitmap(BitmapFactory.decodeFile(croppedImageFile.getAbsolutePath())); } } }