How to centerCrop an image like the same method "centerCrop" do in xml android ? I don't want to crop the center of the image .I have tried the below code but ,it was cropping the center portion of the image,and it produce a square shaped image,I want the same centerCrop function to use in a Canvas on android.Can anyone help?? Hope my question is clear to you.
 Bitmap bitmap=BitmapFactory.decodeResource(res, (R.drawable.ice));
        Bitmap cropBmp;
        if (bitmap.getWidth() >= bitmap.getHeight()){
            cropBmp = Bitmap.createBitmap(
                    bitmap,
                    bitmap.getWidth()/2 - bitmap.getHeight()/2,
                    0,
                    bitmap.getHeight(),
                    bitmap.getHeight()
            );
        }else{
            cropBmp = Bitmap.createBitmap(
                    bitmap,
                    0,
                    bitmap.getHeight()/2 - bitmap.getWidth()/2,
                    bitmap.getWidth(),
                    bitmap.getWidth()
            );
        }
        dstRectForRender.set(50,20 ,500 ,360 );
        canvas2.drawBitmap(cropBmp, null, dstRectForRender, paint);