android - How to cut some part of image and show it in imageview

后端 未结 3 1176
花落未央
花落未央 2020-12-11 03:30

I want to show only some part of image in imageview. See following image . \"image

Same example can be f

3条回答
  •  星月不相逢
    2020-12-11 04:11

    If someone is looking to cut image from the bottom

    // recreate the new Bitmap
    Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, x, y, 
                      width, height, matrix, true); 
    

    replace following params with this logic

    y : (bitmapOrg.getHeight() - 1) - (height of the red box present in the question)

    height : (height of the red box present in the question)

    This way you could avoid exceptions such as(for x you need to modify accordingly)

    IllegalArgumentException: x + width must be <= bitmap.width() in android
    
    IllegalArgumentException: y + width must be <= bitmap.height() in android
    

提交回复
热议问题