Android 安卓:如何使用毕加索裁剪图像?
我想使用Android版毕加索图像库裁剪图像,而不是调整图像大小 更具体地说,我想加载一个图像,然后取一个带有坐标Android 安卓:如何使用毕加索裁剪图像?,android,bitmap,picasso,Android,Bitmap,Picasso,我想使用Android版毕加索图像库裁剪图像,而不是调整图像大小 更具体地说,我想加载一个图像,然后取一个带有坐标(x,y),宽度w,高度h: Original Image ------------------------------ | | | (x,y) | | ------------ | | | | | | |
(x,y)
,宽度w
,高度h
:
Original Image
------------------------------
| |
| (x,y) |
| ------------ |
| | | |
| | Cropped | |
| | Image | h |
| | | |
| | | |
| ------------ |
| w |
------------------------------
然后,我想把这个矩形的原始图像加载到
ImageView
中。我该怎么做 你可以使用毕加索的变换函数。它允许您通过自己的方法对位图
可绘制文件进行必要的更改:
Picasso.with(getContext())
.load(R.drawable.sample) // the image you want to load
.transform(new Transformation() {
@Override
public Bitmap transform(Bitmap source) {
Bitmap result = Bitmap.createBitmap(source,x,y,w,h); // the actual cropping
source.recycle(); // recycle the source bitmap to avoid memory problems
return result;
}
@Override
public String key() {
return x+","+y+","+w+","+h; // some id unique for the transformation you do
}
})
.into(findViewById(R.id.yourImageView); // load the cropped image into your image view
工作得很好!