Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓:如何使用毕加索裁剪图像?_Android_Bitmap_Picasso - Fatal编程技术网

Android 安卓:如何使用毕加索裁剪图像?

Android 安卓:如何使用毕加索裁剪图像?,android,bitmap,picasso,Android,Bitmap,Picasso,我想使用Android版毕加索图像库裁剪图像,而不是调整图像大小 更具体地说,我想加载一个图像,然后取一个带有坐标(x,y),宽度w,高度h: Original Image ------------------------------ | | | (x,y) | | ------------ | | | | | | |

我想使用Android版毕加索图像库裁剪图像,而不是调整图像大小

更具体地说,我想加载一个图像,然后取一个带有坐标
(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

工作得很好!