Crop image to square - Android

后端 未结 4 1921
盖世英雄少女心
盖世英雄少女心 2021-02-05 08:29

How can I cut rectangular image (600 x 300) from left and right to fit in square ImageView ? I don\'t want to resize image, I just want to crop it, to be 300 x 300.

4条回答
  •  独厮守ぢ
    2021-02-05 08:54

    You can use

    Bitmap dst = Bitmap.createBitmap(src, startX, startY, dstWidth, dstHeight);
    

    from the documentation:

    Returns an immutable bitmap from the specified subset of the source bitmap. The new bitmap may be the same object as source, or a copy may have been made. It is initialized with the same density as the original bitmap.

    Here you can find the documentation

提交回复
热议问题