安卓剪裁图片(直接操作bitmap)
来源:互联网 发布:pink ward知乎 编辑:程序博客网 时间:2024/05/18 12:29
/** * 按正方形剪裁图片 * 指定正方形边长 */ public static Bitmap imageCrop(Bitmap bitmap, int width) { // 得到图片的宽,高 int w = bitmap.getWidth(); int h = bitmap.getHeight(); //width最大不能超过长方形的短边 if (w < width || h < width) { width = w > h ? h : w; } int retX = (w - width) / 2; int retY = (h - width) / 2; return Bitmap.createBitmap(bitmap, retX, retY, width, width, null, false); }
/** * 按正方形剪裁图片 * 截最大的正方形 */ public static Bitmap imageCrop(Bitmap bitmap) { // 得到图片的宽,高 int w = bitmap.getWidth(); int h = bitmap.getHeight(); int width = w > h ? h : w; int retX = (w - width) / 2; int retY = (h - width) / 2; return Bitmap.createBitmap(bitmap, retX, retY, width, width, null, false); }
这两种方法截出来的正方形和原图片的中心都是重合的。其实只要善用Bitmap.createBitmap(Bitmap source, int x, int y, int width, int height)这个方法,想截什么样的图都可以。
阅读全文
0 0
- 安卓剪裁图片(直接操作bitmap)
- 安卓Bitmap读取图片
- 安卓图片操作(调用系统相机,预览本地照片,调用系统裁剪图片,压缩图片,中心裁剪方形图片,bitmap转byte[])
- 安卓图片操作:drawable、bitmap、byte[]之间互转,以及drawable的操作
- 安卓OOM和Bitmap图片二级缓存机制(一)
- 安卓OOM和Bitmap图片二级缓存机制(二)
- 安卓图片优化之Bitmap优化(一)
- 安卓OOM和Bitmap图片二级缓存机制(二)
- 安卓OOM和Bitmap图片二级缓存机制(一)
- 安卓OOM和Bitmap图片二级缓存机制(二)
- 安卓OOM和Bitmap图片二级缓存机制(二)
- 安卓图片Bitmap一些旋转处理
- Android 图片操作(Bitmap)
- Android 图片操作(Bitmap)
- Android 图片操作(Bitmap)
- Android图片操作(Bitmap)
- bitmap缩放剪裁图片(等宽裁中间部分高)
- 安卓开发 第八篇 我的安卓应用架构设计-----图片选择以及剪裁
- FFMPEG 之视频解码
- AngularJs+Bootstrap Table $compile动态生成html
- java,this不能和super同时使用 并且放在第一行
- jvm工具看内存泄露
- Eclipse安装Gradle插件
- 安卓剪裁图片(直接操作bitmap)
- 重磅消息!微信或为确保用户账户安全或关停这一功能…
- Idea 启动Sringboot 报错 Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCont
- 关于召开“2017年BIM及智慧管理技术应用交流会(江苏)”的通知
- idea部署项目到远程tomcat——配置本地idea+远程端
- 文章标题
- JAVA的一次编译,到处运行,你知道多少?
- 【海报故事汇】一杆制胜的TopGolf
- Keras学习笔记二:卷积神经网络相关层