I'm trying to add shadow effect do an image. I use a mask to draw the image (I need a specific shape for my image). Can you please tell me how to add shadow effect to my image? I've tried something like paint.setShadowLayer(10, 10, 10, Color.RED) but it didn't worked. Here is the source code:
#Override
public void draw(Canvas canvas) {
Rect rect = new Rect(0, 0, getWidth() - 1, getHeight() - 1);
NinePatchDrawable mask = (NinePatchDrawable) getContext().getResources().getDrawable(maskResId);
mask.setBounds(rect);
Bitmap content = Bitmap.createBitmap(rect.width(), rect.height(), Bitmap.Config.ARGB_8888);
Canvas contentCanvas = new Canvas(content);
super.draw(contentCanvas);
Paint paint = new Paint();
paint.setXfermode(new AvoidXfermode(Color.BLACK, 255, AvoidXfermode.Mode.TARGET));
mask.draw(canvas);
canvas.drawBitmap(content, null, rect, paint);
}
my solution:
class ShadowImage
public class ShadowImage extends BitmapDrawable {
Bitmap bm;
static float shadowRadius = 4f;
static PointF shadowDirection = new PointF(2f, 2f);
int fillColor = 0;
#Override
public void draw(Canvas canvas) {
Rect rect = new Rect(0, 0, bm.getWidth(), bm.getHeight());
Log.i("TEST", rect.toString());
setBounds(rect);
Paint mShadow = new Paint();
mShadow.setAntiAlias(true);
mShadow.setShadowLayer(shadowRadius, shadowDirection.x, shadowDirection.y, Color.BLACK);
canvas.drawRect(rect, mShadow);
if(fillColor != 0) {
Paint mFill = new Paint();
mFill.setColor(fillColor);
canvas.drawRect(rect, mFill);
}
canvas.drawBitmap(bm, 0.0f, 0.0f, null);
}
public ShadowImage(Resources res, Bitmap bitmap) {
super(res, Bitmap.createScaledBitmap(bitmap, (int) (bitmap.getWidth()+shadowRadius*shadowDirection.x), (int) (bitmap.getHeight()+shadowRadius*shadowDirection.y), false));
this.bm = bitmap;
}
public ShadowImage(Resources res, Bitmap bitmap, int fillColor) {
super(res, Bitmap.createScaledBitmap(bitmap, (int) (bitmap.getWidth()+shadowRadius*shadowDirection.x), (int) (bitmap.getHeight()+shadowRadius*shadowDirection.y), false));
this.bm = bitmap;
this.fillColor = fillColor;
}
}
Activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout root = (LinearLayout) findViewById(R.id.root_layout);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
ShadowImage image = new ShadowImage(getResources(), bmp);
ShadowImage image2 = new ShadowImage(getResources(), bmp, Color.WHITE);
ImageView iv_normal = new ImageView(getApplicationContext());
iv_normal.setPadding(10, 10, 10, 10);
iv_normal.setImageBitmap(bmp);
ImageView iv_shadow = new ImageView(getApplicationContext());
iv_shadow.setPadding(10, 10, 10, 10);
iv_shadow.setImageDrawable(image);
ImageView iv_fill = new ImageView(getApplicationContext());
iv_fill.setPadding(10, 10, 10, 10);
iv_fill.setImageDrawable(image2);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
root.addView(iv_normal, params);
root.addView(iv_shadow, params);
root.addView(iv_fill, params);
root.setGravity(Gravity.CENTER);
}
Image:
Related
How to add multiple points over an image view.
this is what i am trying
myView = (ImageView) findViewById(R.id.my_view);
View view = LayoutInflater.from(ZoomTouchActivity.this).inflate(R.layout.layout_custom_view, null);
CircularImageView imgView = view.findViewById(R.id.site_image);
TextView siteName = view.findViewById(R.id.site_text);
imgView.setImageResource(R.drawable.ic_launcher_background);
siteName.setText("est");
Bitmap bitmap = getBitmapFromView(view);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.BLACK);
// canvas.drawCircle(50, 50, 10, paint);
canvas.drawBitmap(bitmap, 50, 50, paint);
myView.setImageBitmap(bitmap);
You can draw on an ImageView by simply putting the image's Bitmap inside a canvas, draw on the canvas and set the drawn canvas to the imageview. You can check this answer for more details. For more details on how to draw, you can check the android documentation here.
Try this:
BitmapFactory.Options myOptions;
Canvas canvas;
Bitmap mutableBitmap;
Bitmap workingBitmap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_open= findViewById(R.id.btn_open);
image2= findViewById(R.id.imageView);
myOptions = new BitmapFactory.Options();
bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.image000880,myOptions);
paint= new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.WHITE);
workingBitmap = Bitmap.createBitmap(bitmap);
mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);
canvas = new Canvas(mutableBitmap);
private void drawpoint(ImageView imageView,float x,float y, int raduis){
myOptions.inDither = true;
myOptions.inScaled = false;
myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// important
myOptions.inPurgeable = true;
// ArrayList<Point> list= new ArrayList<>();
canvas.drawCircle(x,y, raduis, paint);
imageView = (ImageView)findViewById(R.id.imageView);
imageView.setAdjustViewBounds(true);
imageView.setImageBitmap(mutableBitmap);
}
This is my little app. It looks perfect in my device but when I use it in another device with another size screen the rectangle does not fit the screen to the edge.I try to convert pix to dp but it does not work great.
public class MyView extends View {
private static final String TAG = "MyActivity";
Paint paint;
private Rect rectangle;
Paint paint2;
private Rect rectangle2;
Paint paint3;
private Rect rectangle3;
Paint paint4;
private Rect rectangle4;
Paint paint5;
private Rect rectangle5;
Paint paint6;
private Rect rectangle6;
Paint paint7;
private Rect rectangle7;
Paint paint8;
private Rect rectangle8;
Paint paint9;
private Rect rectangle9;
Paint paint10;
private Rect rectangle10;
Paint paint11;
private Rect rectangle11;
Paint paint12;
private Rect rectangle12;
Paint paint13;
private Rect rectangle13;
Paint paint14;
private Rect rectangle14;
Paint paint15;
private Rect rectangle15;
Paint paint16;
private Rect rectangle16;
Paint colorPicker1;
private Rect rectangleRed;
Paint colorPicker2;
private Rect rectangleYellow;
Paint colorPicker3;
private Rect rectangleBlue;
Paint colorPicker4;
private Rect rectangleWhite;
int xStored;
int yStored;
int colorStore1;
public MyView(Context context) {
super(context);
init();
}
private void init(){
Log.i(TAG, "hola "+ screen);
paint = new Paint();
paint.setColor(Color.WHITE);
rectangle = new Rect(0, 0, 100, 100);
paint2 = new Paint();
paint2.setColor(Color.WHITE);
rectangle2 = new Rect(110, 0, 250, 100);
paint3 = new Paint();
paint3.setColor(Color.WHITE);
rectangle3 = new Rect(260, 0, 340, 100);
paint4 = new Paint();
paint4.setColor(Color.WHITE);
rectangle4 = new Rect(350, 0, 480, 100);
paint5 = new Paint();
paint5.setColor(Color.WHITE);
rectangle5 = new Rect(0, 110, 100, 260);
paint6 = new Paint();
paint6.setColor(Color.WHITE);
rectangle6 = new Rect(110, 110, 250, 260);
paint7 = new Paint();
paint7.setColor(Color.WHITE);
rectangle7 = new Rect(260, 110, 340, 260);
paint8 = new Paint();
paint8.setColor(Color.WHITE);
rectangle8 = new Rect(350, 110, 480, 260);
paint9 = new Paint();
paint9.setColor(Color.WHITE);
rectangle9 = new Rect(0, 270, 100, 340);
paint10 = new Paint();
paint10.setColor(Color.WHITE);
rectangle10 = new Rect(110, 270, 250, 340);
paint11 = new Paint();
paint11.setColor(Color.WHITE);
rectangle11 = new Rect(260, 270, 340, 340);
paint12 = new Paint();
paint12.setColor(Color.WHITE);
rectangle12 = new Rect(350, 270, 480, 340);
paint13 = new Paint();
paint13.setColor(Color.WHITE);
rectangle13 = new Rect(0, 350, 100, 440);
paint14 = new Paint();
paint14.setColor(Color.WHITE);
rectangle14 = new Rect(110, 350, 250, 440);
paint15 = new Paint();
paint15.setColor(Color.WHITE);
rectangle15 = new Rect(260, 350, 340, 440);
paint16 = new Paint();
paint16.setColor(Color.WHITE);
rectangle16 = new Rect(350, 350, 480, 440);
colorPicker1 = new Paint();
colorPicker1.setColor(Color.RED);
rectangleRed= new Rect(0, 580 , 120+ screen, 680);
colorPicker2 = new Paint();
colorPicker2.setColor(Color.YELLOW);
rectangleYellow = new Rect(120+ screen, 580, 240+ screen2, 680);
colorPicker3 = new Paint();
colorPicker3.setColor(Color.BLUE);
rectangleBlue = new Rect(240+ screen3, 580, 360,680 );
colorPicker4 = new Paint();
colorPicker4.setColor(Color.WHITE);
rectangleWhite = new Rect(360+ screen, 580, 480+ screen, 680);
}
#Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(BLACK);
canvas.drawRect(rectangle, paint);
canvas.drawRect(rectangle2, paint2);
canvas.drawRect(rectangle3, paint3);
canvas.drawRect(rectangle4, paint4);
canvas.drawRect(rectangle5, paint5);
canvas.drawRect(rectangle6, paint6);
canvas.drawRect(rectangle7, paint7);
canvas.drawRect(rectangle8, paint8);
canvas.drawRect(rectangle9, paint9);
canvas.drawRect(rectangle10, paint10);
canvas.drawRect(rectangle11, paint11);
canvas.drawRect(rectangle12, paint12);
canvas.drawRect(rectangle13, paint13);
canvas.drawRect(rectangle14, paint14);
canvas.drawRect(rectangle15, paint15);
canvas.drawRect(rectangle16, paint16);
canvas.drawRect(rectangleRed, colorPicker1);
canvas.drawRect(rectangleYellow,colorPicker2 );
canvas.drawRect(rectangleBlue,colorPicker3 );
//canvas.drawRect(rectangleWhite,colorPicker4 );
}
#Override
public boolean onTouchEvent( MotionEvent event) {
super.onTouchEvent(event);
int x = (int)event.getX();
int y = (int)event.getY();
xStored = x; yStored=y;
if (event.getAction()==MotionEvent.ACTION_UP){
}else if(event.getAction()==MotionEvent.ACTION_DOWN){
if(rectangleRed.contains(x,y)){
colorStore1 = colorPicker1.getColor();
}
if(rectangleYellow.contains(x,y)){
colorStore1 = colorPicker2.getColor();
}
if (rectangleBlue.contains(x,y)){
colorStore1 = colorPicker3.getColor();
}
if (rectangleWhite.contains(x,y)){
colorStore1 = colorPicker4.getColor();
}
if(rectangle.contains(x,y)){
paint.setColor(colorStore1);
}
if(rectangle2.contains(x,y)){
paint2.setColor(colorStore1);
}
if(rectangle3.contains(x,y)){
paint3.setColor(colorStore1);
}
if(rectangle4.contains(x,y)){
paint4.setColor(colorStore1);
}
if(rectangle5.contains(x,y)){
paint5.setColor(colorStore1);
}
if(rectangle6.contains(x,y)){
paint6.setColor(colorStore1);
}
if(rectangle7.contains(x,y)){
paint7.setColor(colorStore1);
}
if(rectangle8.contains(x,y)){
paint8.setColor(colorStore1);
}
if(rectangle9.contains(x,y)){
paint9.setColor(colorStore1);
}
if(rectangle10.contains(x,y)){
paint10.setColor(colorStore1);
}
if(rectangle11.contains(x,y)){
paint11.setColor(colorStore1);
}
if(rectangle12.contains(x,y)){
paint12.setColor(colorStore1);
}
if(rectangle13.contains(x,y)){
paint13.setColor(colorStore1);
}
if(rectangle14.contains(x,y)){
paint14.setColor(colorStore1);
}
if(rectangle15.contains(x,y)){
paint15.setColor(colorStore1);
}
if(rectangle16.contains(x,y)){
paint16.setColor(colorStore1);
}
}else if(event.getAction()==MotionEvent.ACTION_MOVE){
}
this.postInvalidate();
return true;
}
}
Use the getWidth() and getHeight() methods of View to get width and height at runtime, matching the actual screen.
How to create a layout like shown in image?
I think you can use android:rotation="-45" to put over the image a crossed component and make this effect.
Use this code :
1. Create TriangleImageView.java class in Java folder :
public class TriangleImageView extends ImageView {
public TriangleImageView(Context ctx, AttributeSet attrs) {
super(ctx, attrs);
}
#Override
protected void onDraw(Canvas canvas) {
Drawable drawable = getDrawable();
if (drawable == null) {
return;
}
if (getWidth() == 0 || getHeight() == 0) {
return;
}
Bitmap b = ((BitmapDrawable) drawable).getBitmap();
Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);
int w = getWidth(), h = getHeight();
Bitmap roundBitmap = getRoundedCroppedBitmap(bitmap, w);
canvas.drawBitmap(roundBitmap, 0, 0, null);
}
public static Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
Bitmap finalBitmap;
if (bitmap.getWidth() != radius || bitmap.getHeight() != radius)
finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius,
false);
else
finalBitmap = bitmap;
Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),
finalBitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
Paint paint = new Paint();
final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
finalBitmap.getHeight());
Point point1_draw = new Point(75, 0);
Point point2_draw = new Point(0, 180);
Point point3_draw = new Point(180, 180);
Path path = new Path();
path.moveTo(point1_draw.x, point1_draw.y);
path.lineTo(point2_draw.x, point2_draw.y);
path.lineTo(point3_draw.x, point3_draw.y);
path.lineTo(point1_draw.x, point1_draw.y);
path.close();
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(Color.parseColor("#BAB399"));
canvas.drawPath(path, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(finalBitmap, rect, rect, paint);
return output;
}
}
In Acitivity Use this code :
private imageViewTriangle;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageViewTriangle=(ImageView)findViewById(R.id.imageView_triangle);
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.images);
imageViewTriangle.setImageBitmap(icon);
}
Output is :
Modify it as your need.
Note : ImageView is define in comment because it give me trouble to improve formatting ..
As stated above you can restructure the custom image class as the code below
public class ProfileImageView extends AppCompatImageView{
public ProfileImageView(Context context) {
super(context);
}
public ProfileImageView(Context context, #Nullable AttributeSet attrs) {
super(context, attrs);
}
public ProfileImageView(Context context, #Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
protected void onDraw(Canvas canvas) {
Drawable drawable = getDrawable();
if (drawable == null) {
return;
}
if (getWidth() == 0 || getHeight() == 0) {
return;
}
Bitmap b = ((BitmapDrawable) drawable).getBitmap();
Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);
int w = getWidth(), h = getHeight();
Bitmap roundBitmap = getRoundedCroppedBitmap(bitmap, w,this.getLayoutParams().width,this.getLayoutParams().height);
canvas.drawBitmap(roundBitmap, 0, 0, null);
}
public static Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius, int dimension_w, int dimension_h) {
Bitmap finalBitmap;
if (bitmap.getWidth() != radius || bitmap.getHeight() != radius)
finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius,
false);
else
finalBitmap = bitmap;
Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),
finalBitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
Paint paint = new Paint();
final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
finalBitmap.getHeight());
Log.e("Profile",""+dimension_w);
Point point1_draw = new Point(0, 0);
Point point2_draw = new Point(dimension_w, 0);
Point point3_draw = new Point(dimension_w, (dimension_h/2));
Point point4_draw = new Point(0, dimension_h);
Path path = new Path();
path.moveTo(point1_draw.x, point1_draw.y);
path.lineTo(point2_draw.x, point2_draw.y);
path.lineTo(point3_draw.x, point3_draw.y);
path.lineTo(point4_draw.x, point4_draw.y);
path.lineTo(point1_draw.x, point1_draw.y);
path.close();
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(Color.parseColor("#BAB399"));
canvas.drawPath(path, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(finalBitmap, rect, rect, paint);
return output;
}
}
Sample screen shot
I'm trying to draw two circles like this:
This is how I'm trying to do it:
Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
Canvas c = new Canvas(bmp);
RectF rect = new RectF(0,0,width,width);
Paint paint = new Paint();
drawCircles(paint, c, width, height, width);
ImageView img = (ImageView) findViewById(R.id.imageView1);
img.setImageBitmap(bmp);
img.setScaleType(ScaleType.FIT_CENTER);
And here is my drawCircles() method:
private void drawCircles(Paint paint, Canvas c, int width, int height, int radius) {
paint.setARGB(255, 255 , 10, 21);
paint.setStrokeWidth(10);
paint.setAntiAlias(true);
paint.setStrokeCap(Paint.Cap.BUTT);
paint.setStyle(Paint.Style.STROKE);
if(width < height && radius == 0){
radius = width/2;
height = width;
} else if (radius == 0){
radius = height/2;
width = height;
}
Paint paint2 = new Paint();
paint2.setARGB(255, 255 , 10, 21);
paint2.setStrokeWidth(10);
paint2.setAntiAlias(true);
paint2.setStrokeCap(Paint.Cap.BUTT);
paint2.setStyle(Paint.Style.STROKE);
c.drawCircle(width/2, height/2, radius-10, paint);
c.drawCircle(width/2, height/2, 50, paint2);
}
I don't know why but I get only one circle, the small one (the one drawn with paint2).
What can be the reason?
Try this code.Hope it may helps :)
public class SimpleCircleActivity extends Activity
{
private CircleDemoView circledemoView ;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
circledemoView =new CircleDemoView(this);
setContentView(circledemoView);
}
private class CircleDemoView extends View
{
public CircleDemoView(Context context)
{
super(context);
}
#Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
Paint p = new Paint();
p.setColor(Color.RED);
DashPathEffect dashPath = new DashPathEffect(new float[]{5,5}, (float)1.0);
p.setPathEffect(dashPath);
p.setStyle(Style.STROKE);
for (int i = 0; i < 2; i ++) {
canvas.drawCircle(200, 200, 50+(i*40), p);
}
invalidate();
}
}
}
In my application I am taking the image from the gallery and the shape of that image is in square I want to set that image to an imageView then it should be oval shape. I.e in my case I need to crop that image like human face. can anybody tell me how to do that thanks in advance.
Use the following class instead of image view.
RoundedCornerImageView imageView1;
imageView1.setRadius(10);
This will make the image radius by 10 px, you can give wat value you want and make it as the shape you want. Have a try.
All the best :)
public class RoundedCornerImageView extends ImageView {
private int radius = 10;
public RoundedCornerImageView(Context context) {
super(context);
}
protected void onDraw(Canvas canvas) {
Path clipPath = new Path();
int w = this.getWidth();
int h = this.getHeight();
clipPath.addRoundRect(new RectF(0, 0, w, h), radius, radius, Path.Direction.CW);
canvas.clipPath(clipPath);
super.onDraw(canvas);
}
public RoundedCornerImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public RoundedCornerImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setRadius(int radius){
this.radius = radius;
this.invalidate();
}
}
You can use this
public Drawable getRoundedCornerImage(Drawable bitmapDrawable) {
Bitmap bitmap = ((BitmapDrawable)bitmapDrawable).getBitmap();
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = 100;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
Drawable image = new BitmapDrawable(output);
return image;
}
Hope this helps you
Also you can use this or Download demo code example
public class Shape {
private Bitmap bmp;
private ImageView img;
public Shape(Bitmap bmp, ImageView img) {
this.bmp=bmp;
this.img=img;
onDraw();
}
private void onDraw(){
Canvas canvas=new Canvas();
if (bmp.getWidth() == 0 || bmp.getHeight() == 0) {
return;
}
int w = bmp.getWidth(), h = bmp.getHeight();
Bitmap roundBitmap = getOvalCroppedBitmap(bmp, w);
img.setImageBitmap(roundBitmap);
}
public static Bitmap getOvalCroppedBitmap(Bitmap bitmap, int radius) {
Bitmap finalBitmap;
if (bitmap.getWidth() != radius || bitmap.getHeight() != radius)
finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius,
false);
else
finalBitmap = bitmap;
Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),
finalBitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
Paint paint = new Paint();
final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
finalBitmap.getHeight());
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(Color.parseColor("#BAB399"));
RectF oval = new RectF(0, 0, 130, 150);
canvas.drawOval(oval, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(finalBitmap, rect, oval, paint);
return output;
}
Finally, on your main activity, instantiate your class Shape and pass two parameters to your class. The image to be cropped to oval and the imageview where your final image will be set.
Download demo code example