How can I crop a bitmap for ImageView?

前端 未结 4 920

I know this should be simple , but android:scaleType=\"centerCrop\" doesn\'t crop Image

I got image 1950 pixels wide and need it to be cropped

4条回答
  •  星月不相逢
    2020-11-30 05:56

    You can also crop image by programmatically using createBitmap.

    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
    bm = Bitmap.createBitmap(bm, 0, 0, 400, 400);
    your_imageview.setImageBitmap(bm);
    

    Here 400 is your width & height you can change as per your requirement.

提交回复
热议问题