android – How can I display a specific part of an image in an ImageView?


I have a list of photos that I display in a ListView using an adapter.

Right now I am displaying the photo like this:

PhotoAdapter.ViewHolder viewHolder;
        if (view == null) {
            view = inflater.inflate(R.layout.list_view_photo_item, viewGroup, false);

            viewHolder = new PhotoAdapter.ViewHolder(view);
        } else {
            viewHolder = (PhotoAdapter.ViewHolder) view.getTag();


This is a normal display. And my task is to display a photo at the specified coordinates (upper left, upper right, lower left and lower right point). That is, I do not want to display the entire photo, but only this piece of the photo that the user previously selected as a preview, and I want to display it. The server returns me completely all photos + coordinates (in PX) of this preview. Who can advise what?


The transform method and the Transformation interface allow you to change the image to your liking:

       .transform(new Transformation {

            @Override public Bitmap transform(Bitmap source) {
                Bitmap result = Bitmap.createBitmap(source, x, y, width, height);
                if (result != source)
                return result;

           @Override public String key() { return "crop()"; }
Scroll to Top