android图片处理
来源:互联网 发布:滁州安广网络客服电话 编辑:程序博客网 时间:2024/05/14 08:29
<span style="font-size:18px;"><span style="white-space:pre"></span>/** * 对位图进行等比例缩放,需要传入要缩放位图的流入量,与原始宽度及高度 * @param inputsream,输入流 * @param width ,需要设置的宽度 * @param height,需要设置的高度 * @return 返回缩放后的图片 * @throws IOException */public static Bitmap Scalebitmap(InputStream inputsream,int width,int height) throws IOException{byte[] buffer = new byte[512];ByteArrayOutputStream bos= new ByteArrayOutputStream();int length;while((length=inputsream.read(buffer))!=-1){bos.write(buffer, 0, length);}byte[] byteArray = bos.toByteArray();Options opts=new Options();opts.inJustDecodeBounds=true;BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length, opts);width=opts.outWidth/width;height=opts.outHeight/height;int scale = width>height?width:height;opts.inJustDecodeBounds=false;opts.inSampleSize=scale;Bitmap bm = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length, opts);return bm;}</span>
<span style="font-size:18px;"><span style="white-space:pre"></span></span>
图片的程序缓存及本地缓存操作:
<pre style="margin-top: 15px; padding: 6px 10px; border: 1px solid rgb(204, 204, 204); font-size: 13px; font-family: Consolas, 'Liberation Mono', Courier, monospace; line-height: 19px; overflow: auto; border-radius: 3px; color: rgb(51, 51, 51); margin-bottom: 0px !important; background-color: rgb(248, 248, 248);"><code style="margin: 0px; padding: 0px; border: none; font-size: 12px; font-family: Consolas, 'Liberation Mono', Courier, monospace; border-radius: 3px; background: transparent;">=====================================================================// 程序声明缓存数据private Map<String, SoftReference<Bitmap>> cache = new HashMap<String, SoftReference<Bitmap>>();//将图片保存到软缓存中cache.put(path, new SoftReference<Bitmap>(bm));// 从缓存中寻找看是否有该图SoftReference<Bitmap> softReference = cache.get(path);if (softReference != null) { Bitmap bm = softReference.get();}======================================================================//将bitmap图片保存到本地缓存目录中String filename = path.substring(path.lastIndexOf("/") + 1);File file = new File(context.getCacheDir(), filename);targetFile=file.getAbsolutePath();// 父目录不存在 则创建父目录 if (!targetFile.getParentFile().exists()) { targetFile.getParentFile().mkdirs(); } FileOutputStream fos = new FileOutputStream(targetFile); bitmap.compress(CompressFormat.JPEG, 100, fos);====================================================================//本地文件缓存中读取图片String filename = path.substring(path.lastIndexOf("/") + 1);File file = new File(MusicApplication.getcontext().getCacheDir(), filename);File file = new File();//判断本地缓存中是否有该图片if (!file.exists()){ return null;}else{ return BitmapFactory.decodeFile(file.getAbsolutePath());}===================================================================</code>
<span style="font-size:18px;"></span>
1 0
- android图片处理一
- android 图片放大处理
- android 处理图片资源
- Android处理图片
- android图片处理技巧
- android处理图片
- Android图片处理技巧
- Android图片处理技巧
- android图片处理方法
- android 图片处理
- Android 图片处理特效
- android 图片处理
- android 图片处理
- android 图片处理
- android图片处理方法
- android图片处理
- android 处理图片工具
- Android图片处理
- 游戏设计之我见 —— 动作游戏中敌人的受击设计
- 浅谈几种iOS定时器
- windbg vmware win7联机调试环境搭建
- java 正则表达式group方法详解 group() group(int n)
- 蓝牙SDP剖析(二) 之 PDU ID解析
- android图片处理
- UNITY_INITIALIZE_OUTPUT
- 汉宁窗的性质
- 学生信息管理系统--常见问题
- 混用ngui和ugui渲染顺序问题
- CoreOS的适应场景介绍
- 重写virtual时不写关键字会发生什么
- HZAU 1001 Handing Out Candies
- 在OpenCV环境下写的两个图像平移C和C++源代码!