设置bitmap的宽高,同时将bitmap转换为file对象
来源:互联网 发布:苹果手机网络被劫持 编辑:程序博客网 时间:2024/05/29 14:32
public class BitmapToSizeChangeFile { /** * 将bitmap转换为file存储起来 * @param bitmap * @return */ public static File bitmapChangeFile(Bitmap bitmap) { FileOutputStream fileOutStream = null; File file = null; try { //通过相关方法生成一个Bitmap类型的对象,生产文件选择用当前事件的long型作为文件路径 file = new File(Environment.getExternalStorageDirectory(), System.currentTimeMillis()+".png"); fileOutStream = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutStream); // 把位图输出到指定的文件中 fileOutStream.flush(); } catch (Exception e) { e.printStackTrace(); }finally { try { fileOutStream.close(); } catch (IOException e) { e.printStackTrace(); } } return file; } /** * 处理图片 * @param bm 所要转换的bitmap * @param newWidth 新的宽 * @param newHeight 新的高 * @return 指定宽高的bitmap */ public static Bitmap zoomImg(Bitmap bm, int newWidth ,int newHeight){ // 获得图片的宽高 int width = bm.getWidth(); int height = bm.getHeight(); // 计算缩放比例 float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // 取得想要缩放的matrix参数 Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); // 得到新的图片 Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true); return newbm; }}
阅读全文
0 0
- 设置bitmap的宽高,同时将bitmap转换为file对象
- 获取View的截图-将View转换为Bitmap对象
- 将Bitmap转换成File
- 将bitmap设置为背景的问题解决
- 将一个view对象转换为bitmap对象
- 将Bitmap保存为文件File的方法
- 将图片的BitMap类转化为File文件
- 如何将YUV的byte数组转换为bitmap
- C#将Bitmap转换为Icon
- 将HBITMAP类型转换为BITMAP结构
- bitmap将头像转换为圆形头像
- 将view对象转化为Bitmap
- 将view对象转化为Bitmap
- 将view对象转化为Bitmap
- 将流转换为BitMap对象
- 网络图片资源设置转换为Bitmap
- bitmap转化为file
- bitmap保存为file
- python_浅copy用法
- 开课一周
- tcp连接失败触发的异常
- 在Eclipse软件中用git从服务器导出项目
- LinkedList类注释翻译、源码分析
- 设置bitmap的宽高,同时将bitmap转换为file对象
- Keil C51对外设操作的编程——旧文重读
- CJOJ 2485 UVa 11991 生日礼物/UVa 11991 Easy Problem from Rujia Liu?
- 整理java7中几种常见同步辅助类-CountDownLatch
- iOS粒子动画
- 根据打印机名获取打印机相关参数
- springmvc常用注解标签详解
- 酷壳网,有好多好的文章
- Android中Java调用C/C++