Question:
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);
view.setTag(viewHolder);
} else {
viewHolder = (PhotoAdapter.ViewHolder) view.getTag();
}
picasso.load(photo.getImageUrl())
.placeholder(R.drawable.bg_small_11)
.into(viewHolder.image);
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?
Answer:
The transform method and the Transformation interface allow you to change the image to your liking:
picasso.load(photo.getImageUrl())
.placeholder(R.drawable.bg_small_11)
.transform(new Transformation {
@Override public Bitmap transform(Bitmap source) {
Bitmap result = Bitmap.createBitmap(source, x, y, width, height);
if (result != source)
source.recycle();
return result;
}
@Override public String key() { return "crop()"; }
})
.into(viewHolder.image);