根据路径获取图片,缩放图片
来源:互联网 发布:ubuntu pdf转word 编辑:程序博客网 时间:2024/05/17 09:41
记录几个常用的图片相关操作方法;
////根据路径获取图片,指定尺寸进行压缩private Bitmap decodeThumbBitmapForFile(String path, int w, int h){BitmapFactory.Options opts = new BitmapFactory.Options();opts.inJustDecodeBounds = true;//opts.inPreferredConfig = Bitmap.Config.RGB_565; //如果不要求透明度可用此模式,更省内存//获取图片尺寸BitmapFactory.decodeFile(path, opts);int width = opts.outWidth;int height = opts.outHeight;float scaleWidth = 0.f, scaleHeight = 0.f;if (width > w || height > h) {//计算比例scaleWidth = ((float) width) / w;scaleHeight = ((float) height) / h;}opts.inJustDecodeBounds = false;//float scale = Math.max(scaleWidth, scaleHeight); //取较大或小数Math.min(,);//图片压缩比例,此数越大图片越小;(如为2,长宽都为原来的1/2,即图片为原图1/4份)opts.inSampleSize = (int)scale; //取整Math.ceil(scale)////弱引用,更易被系统回收WeakReference<Bitmap> weak = new WeakReference<Bitmap>(BitmapFactory.decodeFile(path, opts));return Bitmap.createScaledBitmap(weak.get(), w, h, true);}
//////////另一种方式读取图片FileInputStream public static Bitmap loadFromSdCard(String filePath) {File file = new File(filePath);Bitmap bmp = null;try {BitmapFactory.Options opts = new BitmapFactory.Options();opts.inJustDecodeBounds = false;opts.inPreferredConfig = Bitmap.Config.RGB_565;opts.inSampleSize = 2;FileInputStream fis = new FileInputStream(file);bmp = BitmapFactory.decodeStream(fis, null, opts);if(fis!=null){ try {fis.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}if (bmp != null) {return bmp;}} catch (FileNotFoundException e) {e.printStackTrace();}return null;}
////将图片进行缩放public static Bitmap scaleBitmap(Bitmap bmp, float newWidth, float newHeight) {if (bmp != null) { int w= bm.getWidth(); int h = bm.getHeight(); // 计算比例 float scaleWidth = ((float) newWidth) / w; float scaleHeight = ((float) newHeight) / h; Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight);if (scaleWidth== 1.0f && scaleHeight== 1.0f) {return bmp;}Bitmap newbm = Bitmap.createBitmap(bmp, 0, 0, w,h, matrix, true);//return newbm;}return null;}
0 0
- 根据路径获取图片,缩放图片
- Android根据图片路径获取图片名字
- 根据路径获取视频、图片的缩略图
- 根据图片路径来获取图片的真实大小
- Android手机读取相册图片,根据URI获取图片路径
- Android 获取图库图片 根据uri获取路径
- android 根据图片路径和大小获取缩图
- Android根据文件路径获取图片的名字
- 根据url路径获取图片并显示到ListView中
- Android之根据图片的Uri获取对应的路径
- 根据图片在ftp路径获取InputStream流
- 根据网址获取图片
- 根据颜色获取图片
- Android 把bitmap转换成String,计算图片的缩放值,根据路径获得突破并压缩返回bitmap用于显示,获取保存 隐患检查的图片文件夹名称,获取保存图片的目录,根据路径删除图片,添加到图库
- 根据源图片缩放保留透明部分
- 根据滑动距离图片做缩放
- Android根据屏幕宽度,按比例缩放图片
- Android根据屏幕宽度缩放图片
- 隐藏或删除 win7 启动管理器bootmgr
- 零零碎碎的问题总结
- POJ 1797 Heavy Transportation
- Struts2的OGNL与struts2标签
- 会计师事务所验资报告收费标准
- 根据路径获取图片,缩放图片
- python3编码
- StringEscapeUtils类转义与反转义(对js sql html xml等代码进行转义)
- XMPP 两个客户端实现文件传输
- Objective-C Runtime 运行时之一:类与对象
- 重装jdk后的eclipse等环境配置
- finalize()方法与system.gc()方法
- python中位置参数、关键字参数和默认参数
- activity service 通讯