Скажем, у меня есть изображение, похожее на изображение слева ... Каждый флаг 30x20px.Как обрезать части большого изображения в ImageView
Как отобразить область от 0,60 до 30,80? Я также хотел бы, чтобы это было так высококлассно.
Скажем, у меня есть изображение, похожее на изображение слева ... Каждый флаг 30x20px.Как обрезать части большого изображения в ImageView
Как отобразить область от 0,60 до 30,80? Я также хотел бы, чтобы это было так высококлассно.
Вы можете использовать этот метод для создания другого растрового изображения из вашего смещения
/**
* 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.
*
* @param source The bitmap we are subsetting
* @param x The x coordinate of the first pixel in source
* @param y The y coordinate of the first pixel in source
* @param width The number of pixels in each row
* @param height The number of rows
* @return A copy of a subset of the source bitmap or the source bitmap itself.
* @throws IllegalArgumentException if the x, y, width, height values are
* outside of the dimensions of the source bitmap, or width is <= 0,
* or height is <= 0
*/
public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height) {
return createBitmap(source, x, y, width, height, null, false);
}
Другой вариант заключается в создании пользовательского ImageView, затем переопределить onDraw()
метод для рисования растрового изображения на Canvas
от ваших смещений
использования этот метод от Canvas
класс
public void drawBitmap(@NonNull Bitmap bitmap, float left, float top, @Nullable Paint paint) { }