Raster cropping?

so I have this bitmap that I want to use as the background for the view, but the bitmap can sometimes be larger than the view.

let's say my bitmap is 500x500 px and my look is 200x200px

when I set the bitmap as the background for the view, the view is stretched to the size of the bitmap (500x500) ...

I tried setting gravity to clip_horizontal | clip_vertical, but that didn't help ...

<?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/old_wall" android:tileMode="repeat" android:gravity="top|left|clip_horizontal|clip_vertical" /> 

how can i get a bitmap to crop instead of a stretched view to the size of the bitmap?

+4
source share
1 answer

You can always copy the original bitmap in the code. Then set it to the view. Where x, y are your starting points and X_WIDTH , Y_HEIGHT is your ending point. And iv is your ImageView goal:

 Bitmap bmSource; Bitmap bmTarget; bmTarget = Bitmap.createBitmap(bmSource, x, y, X_WIDTH, Y_HEIGHT); iv.setImageBitmap(bmTarget); 
+1
source

Source: https://habr.com/ru/post/1382568/


All Articles