CropImageView icon indicating copy to clipboard operation
CropImageView copied to clipboard

Super easy component for Android to crop an image

CropImageView - Android

Super easy component for Android to crop an image

Installation

Example


<com.joshholtz.cropimageview.CropImageView
        android:id="@+id/crop_image_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#666666"
        android:src="@drawable/josh_hood"
        />


public class MainActivity extends Activity {

	CropImageView cropImageView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		cropImageView = (CropImageView) this.findViewById(R.id.crop_image_view);
		cropImageView.setImageResource(getResources(), R.drawable.josh_hood);
		
		// OPTIONAL - set corner color size and crop area color
//		cropImageView.setCornerDrawable(Color.rgb(255, 200, 0), 100, 100);
//		cropImageView.setCropAreaDrawable(Color.LTGRAY, 150, Color.CYAN, 200, 8);
		
		// OPTIONAL - keep crop square
//		cropImageView.setKeepSquare(true);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);

		return(super.onCreateOptionsMenu(menu));
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if (item.getItemId() == R.id.action_crop) {
			try {
				DisplayActivity.imageToShow = cropImageView.crop(this);
				
				Intent intent = new Intent(this, DisplayActivity.class);
				this.startActivity(intent);
			} catch (IllegalArgumentException e) {
				// Crop section is out of bounds of image
			}
		}
		
		return(super.onOptionsItemSelected(item));
	}
	
}

Author

Josh Holtz, [email protected], @joshdholtz

License

CropImageView is available under the MIT license. See the LICENSE file for more info.