picasso 将图片裁剪成一个正方形
2017-01-18 18:54
344 查看
实现picasso 中的转换方法
裁剪后缩放
裁剪后缩放
public class TransformSquare implements Transformation { private float size; private String key; public TransformSquare(float size, String key) { this.size = size; this.key = key; } /** * @param source 需要加工的图片 * @return */ @Override public Bitmap transform(Bitmap source) { int height = source.getHeight(); int width = source.getWidth(); Bitmap target = null; Matrix matrix = new Matrix(); //宽高相等 if (height == width) { float scale = 1.0f * size / width; //设置x,y缩放比例 matrix.setScale(scale, scale); target = Bitmap.createBitmap(source, 0, 0, width, height, matrix, false); //宽高不相等 } else { int fromX = 0, fromY = 0; int fSize = 0; //确定正方形变长 fSize = Math.min(width, height); //计算正方形在原图 的开始裁剪点 fromX = ((width - fSize) / 2); fromY = ((height - fSize) / 2); //先剪出一个正方形 Bitmap bitmap = Bitmap.createBitmap(source, fromX, fromY, fSize, fSize); float scale = 1.0f * size / fSize; //设置x,y缩放比例 matrix.setScale(scale, scale); target = Bitmap.createBitmap(bitmap, 0, 0, fSize, fSize, matrix, false); bitmap.recycle(); } source.recycle(); return target; } @Override public String key() { return key; } }
相关文章推荐
- 一个圆角Panel,基于四个裁剪的圆角图片,内部用Table布局
- 裁剪图片CropImg的一个小例子【N年前得】
- 一个裁剪图片的小工具类,通过一句代码调用
- OkHttp框架从入门到放弃,解析图片使用Picasso裁剪,二次封装OkHttpUtils,Post提交表单数据
- OkHttp框架从入门到放弃,解析图片使用Picasso裁剪,二次封装OkHttpUtils,Post提交表单数据
- 一个裁剪图片的过程
- 把一个图片裁剪成圆形或者自定义的图形
- android图片裁剪截取中间正方形部分
- megapix-image.js使用的一个坑-ios图片裁剪之画布绘制大图片
- 毕加索的艺术——Picasso,一个强大的Android图片下载缓存库,OkHttpUtils的使用,二次封装PicassoUtils实现微信精选
- 仿一个wp7中PhotoChooserTask指定宽高后的图片裁剪窗口
- 一个利用html5的图片裁剪功能(已解决ios压扁缩放等bug)
- (裁剪只定宽高的图片)一个简单的图片截取代码、等比例、不失真
- 【代码】将任意形状的图片裁剪成一个带圆环的头像(附效果图)
- Picasso:一个专为Android打造的强大的图片下载和缓存库
- SilvetLight 实现的一个上传图片时功能动态裁剪部分区域和缩放图片的功能
- ASP.NET 你肯定会用到的图片裁剪功能,可按长度或宽度裁剪,也能绘制一个更大图
- 位图上下文 裁剪图片成一个圆形的头像
- 一个简单的图片裁剪Activity:android-crop
- Picasso 框架的简单使用 图片缓存 重用 和加载 裁剪