记录一些常用的utils方法
2015-09-30 16:02
316 查看
添加一些工具类,防止自己忘了,利于以后查看
一:把bitmap进行保存
二:bitmap生成base64
三:base64生成bitmap
四:判断是单击,还是双击
以后会慢慢添加
一:把bitmap进行保存
/** * @param getimage 图片 * @param path 路径 * @param format 图片以什么格式保存 * @param quality 图片以什么质量保存 * @return File 图片保存后的文件 */ public static File saveBitmapToFile(Bitmap getimage, String path, Bitmap.CompressFormat format, int quality) { final File file = new File(path); FileOutputStream fos = null; try { if (file.exists() && file.delete()) { } if (file.createNewFile()) { fos = new FileOutputStream(file); getimage.compress(format, quality, fos); } } catch (IOException e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { } } } return file; }
二:bitmap生成base64
/** * @param imgPath 图片地址 * @return */ public static String imgToBase64(String imgPath) { Bitmap bitmap = null; if (imgPath !=null && imgPath.length() > 0) { bitmap = readBitmap(imgPath); } if(bitmap == null){ Log.w("图片不存在",""); } ByteArrayOutputStream out = null; try { out = new ByteArrayOutputStream(); if(bitmap != null){ bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); } out.flush(); out.close(); byte[] imgBytes = out.toByteArray(); return Base64.encodeToString(imgBytes, Base64.DEFAULT); } catch (Exception e) { // TODO Auto-generated catch block return null; } finally { try { if(out != null) { out.flush(); out.close(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } private static Bitmap readBitmap(String imgPath) { try { return BitmapFactory.decodeFile(imgPath); } catch (Exception e) { // TODO Auto-generated catch block return null; } }
三:base64生成bitmap
/** * * @param base64Data base64 * @return */ public static Bitmap stringToBitmap(String base64Data){ //将字符串转换成Bitmap类型 Bitmap bitmap=null; try { byte[] bitmapArray; bitmapArray=Base64.decode(base64Data, Base64.DEFAULT); bitmap=BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length); } catch (Exception e) { e.printStackTrace(); } return bitmap; }
四:判断是单击,还是双击
public class DoubleKUtils { private static long lastClickTime = 0; private static long Time_Interval = 500; public static boolean isFastDoubleClick() { long curTime = System.currentTimeMillis(); long interval = curTime - lastClickTime; if (0 < interval && interval < Time_Interval) { return true; } lastClickTime = curTime; return false; } public static void setTimeInterval(long time) { Time_Interval = time; } }
以后会慢慢添加
相关文章推荐
- 一次奇怪的问题定位过程
- ubuntu 14.04安装oracle java
- Linux 网络编程学习---协议栈
- 多线程并行执行及调度管理-两种实现方式
- Delphi 转圈 原型进度条
- UITextField键盘弹出调整承载textField的视图使其不被遮挡
- linux常用命令(64):crontab命令
- Python抓取网页动态数据——selenium webdriver的使用
- Git命令行模式伪BUG
- TCMalloc 安装与使用
- java中数据流的简单介绍
- HDU 5201 The Monkey King
- Xcode更新新版本后插件无法使用的解决办法
- Git使用教程1:下载及安装
- idea languagelevel问题
- liunx 基本命令
- 京东2016年校招笔试题
- python 装饰器 @用法初探
- LeetCode题解——Convert Sorted List to Binary Search Tree
- [Environment setup]python+selenium+Eclipse+pydev环境搭建