android开发步步为营之111:将图片转换成指定宽和高
来源:互联网 发布:手机截取在线视频软件 编辑:程序博客网 时间:2024/05/16 04:34
//将bitmap转成和GlSurfaceView一样的宽和高Bitmap bitmap = BitmapFactory.decodeStream(getAssets().open(fileName));//方法一:使用MatrixMatrix matrix=new Matrix();matrix.postScale((float)glView.getWidth()/bitmap.getWidth(), (float)glView.getHeight()/bitmap.getHeight());bitmap=Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(),matrix,true);
//方法二:使用系统自动的工具类 add in api 8bitmap= ThumbnailUtils.extractThumbnail(bitmap, glView.getWidth(), glView.getHeight());
查看方法二的源代码
/** * Creates a centered bitmap of the desired size. * * @param source original bitmap source * @param width targeted width * @param height targeted height * @param options options used during thumbnail extraction */ public static Bitmap extractThumbnail( Bitmap source, int width, int height, int options) { if (source == null) { return null; } float scale; if (source.getWidth() < source.getHeight()) { scale = width / (float) source.getWidth(); } else { scale = height / (float) source.getHeight(); } Matrix matrix = new Matrix(); matrix.setScale(scale, scale); Bitmap thumbnail = transform(matrix, source, width, height, OPTIONS_SCALE_UP | options); return thumbnail; }
Bitmap b1; if (scaler != null) { // this is used for minithumb and crop, so we want to filter here. b1 = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), scaler, true); } else { b1 = source; }
发现其实还是按照方法一来实现的
1 0
- android开发步步为营之111:将图片转换成指定宽和高
- android将图片转化为指定的宽和高
- android将图片转化为指定的宽和高
- android开发步步为营之66:android图片选取
- 图片的宽和高
- 获取图片宽和高
- android开发步步为营之81:android图片处理技术之一(截取与缩放)
- android开发步步为营之103:android分享音频视频图片和文字功能的实现
- android开发步步为营之9:反编译apk
- android开发步步为营之14:App Widgets
- android开发步步为营之20:网络设置
- android开发步步为营之28:自定义Menu
- 将任意图片转换成指定大小的图片
- android开发步步为营之43:listview的使用(下篇:显示图片和按钮)
- android开发步步为营之58:给图片绘制圆形气泡背景效果
- android开发步步为营之89: Executor+LruCache动态加载图片,保证不导致OOM
- android开发步步为营之90:android图片处理技术之三(Gradient渐变图片的绘制)
- Android之---获取手机屏幕、应用的宽和高
- JavaWeb基础+oracle实现简单简单分页商品浏览与加入购物车系统
- spring集成reids
- 算法-第四版-练习1.3.1解答
- 面向对象实现文件上传(PHP)
- html格式化
- android开发步步为营之111:将图片转换成指定宽和高
- ie下的3像素和双倍bug问题
- iOS navigation 透明处理
- 数据存储 (读,写)
- C#连接Oracle数据库(直接引用dll使用-Oracle.ManagedDataAccess.dll)
- MySQL 8.0-dmr 版本下载地址
- Codeforces Round #291 (Div. 2)-C. Watto and Mechanism(Trie树)
- php调用原生java程序
- 一个简单窗口(便于窗口消息的理解)